custom show command for mysql and schema description

This commit is contained in:
shivansh02 2024-03-03 23:15:07 +05:30
parent 925f99cfef
commit 2b755d8ade
3 changed files with 26 additions and 4 deletions

View File

@ -1092,15 +1092,15 @@ properties:
description: | description: |
Command to use instead of "mysqldump". This can be used Command to use instead of "mysqldump". This can be used
to run a specific mysql_dump version (e.g., one inside to run a specific mysql_dump version (e.g., one inside
a running docker container). Defaults to "mysqldump". a running container). Defaults to "mysqldump".
example: docker exec mysql_container mysqldump example: docker exec mysql_container mysqldump
mysql_command: mysql_command:
type: string type: string
description: | description: |
Command to run instead of "mysql". This Command to run instead of "mysql". This
can be used to run a specific mysql can be used to run a specific mysql
version (e.g., one inside a running docker version (e.g., one inside a running container).
container). Defaults to "mysql". Defaults to "mysql".
example: docker exec mysql_container mysql example: docker exec mysql_container mysql
format: format:
type: string type: string

View File

@ -35,8 +35,9 @@ def database_names_to_dump(database, extra_environment, log_prefix, dry_run):
if dry_run: if dry_run:
return () return ()
mysql_show_command = database.get('mysql_command') or 'mysql'
show_command = ( show_command = (
('mysql',) (mysql_show_command,)
+ (tuple(database['list_options'].split(' ')) if 'list_options' in database else ()) + (tuple(database['list_options'].split(' ')) if 'list_options' in database else ())
+ (('--host', database['hostname']) if 'hostname' in database else ()) + (('--host', database['hostname']) if 'hostname' in database else ())
+ (('--port', str(database['port'])) if 'port' in database else ()) + (('--port', str(database['port'])) if 'port' in database else ())

View File

@ -142,6 +142,27 @@ def test_database_names_to_dump_runs_mysql_with_list_options():
assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar') assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar')
def test_database_names_to_dump_runs_non_default_mysql_with_list_options():
database = {
'name': 'all',
'list_options': '--defaults-extra-file=my.cnf',
'mysql_command': 'custom_mysql',
}
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
extra_environment=None,
full_command=(
'custom_mysql', # Custom MySQL command
'--defaults-extra-file=my.cnf',
'--skip-column-names',
'--batch',
'--execute',
'show schemas',
)
).and_return(('foo\nbar')).once()
assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar')
def test_execute_dump_command_runs_mysqldump(): def test_execute_dump_command_runs_mysqldump():
process = flexmock() process = flexmock()
flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump') flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')