def test_call_sql_wrapper_with_ssl(self, subprocess_mock): self.constants_mock.DATABASE_USE_SSL = True defaults = self._get_default_options_from_mock() command = MYSQLDUMP + defaults + [self.constants_mock.DATABASE_NAME] sql_wrapper.call_mysqldump(self.constants_mock) self.assert_subprocess_call(subprocess_mock, command)
def test_call_sql_wrapper_with_creds_file(self, subprocess_mock): self.constants_mock.DO_NOT_USE_CREDENTIALS_FILE = False defaults = self._get_default_options_from_mock() command = MYSQLDUMP + defaults + [self.constants_mock.DATABASE_NAME] sql_wrapper.call_mysqldump(self.constants_mock) self.assert_subprocess_call(subprocess_mock, command)
def test_call_mysqldump_with_options(self, subprocess_mock): defaults = self._get_default_options_from_mock() command = MYSQLDUMP + defaults + OPTIONS + [ self.constants_mock.DATABASE_NAME ] sql_wrapper.call_mysqldump(self.constants_mock, OPTIONS) self.assert_subprocess_call(subprocess_mock, command)
def test_call_mysqldump_skips_date(self, subprocess_mock): self.constants_mock.SKIP_DATE = True defaults = self._get_default_options_from_mock() command = MYSQLDUMP + defaults + [ self.constants_mock.DATABASE_NAME, "--skip-dump-date" ] sql_wrapper.call_mysqldump(self.constants_mock) self.assert_subprocess_call(subprocess_mock, command)
def export_data(): """Exports database table data into a text file ordered by primary key.""" logging.info("Exporting data for '%s' tables", mysql_exporter_constants.DATABASE_NAME) options = [ "--order-by-primary", "--tab=" + mysql_exporter_constants.TEMP_FOLDER ] sql_wrapper.call_mysqldump(mysql_exporter_constants, options)
def export_schema(): """Exports the database schema into a sql file.""" logging.info("Exporting the schema for database '%s'", mysql_exporter_constants.DATABASE_NAME) options = ["--no-data"] schema_file = sql_wrapper.call_mysqldump(mysql_exporter_constants, options) logging.debug("Schema dump output:\n%s", schema_file) schema_path = os.path.join( mysql_exporter_constants.TEMP_FOLDER, mysql_exporter_constants.DATABASE_NAME + mysql_exporter_constants.SCHEMA_FILE_SUFFIX) file_writer.write(schema_path, schema_file)