1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- def create_archive_db(self, database=None):
- """
- Create the Destination database
- It checks that if the Destination database exists, the show create
- statement are the same than Source which is useful to detect Db schema
- upgrade
- """
- # Check if db exists
- archive_db_exists = self.archive_db_exists(database=database)
- # retrieve source db create statement
- # if archive database exists, compare create statement
- # else use the statement to create it
- src_db_create_statement = self.get_src_create_db_statement(
- database=database)
- if archive_db_exists:
- logging.debug("Destination DB has '%s' database",
- self.archive_db_name)
- dst_db_create_statement = self.get_dst_create_db_statement(
- database=self.archive_db_name)
- # compare create statement substituing db name in dst (arbitrary
- # choice)
- to_compare_dst_db_create_statement = re.sub(
- 'DATABASE `{dst_db}`'.format(dst_db=self.archive_db_name),
- 'DATABASE `{src_db}`'.format(src_db=database),
- dst_db_create_statement)
- if src_db_create_statement == to_compare_dst_db_create_statement:
- logging.info("source and destination database are identical")
- else:
- logging.debug(
- difflib.SequenceMatcher(
- None, src_db_create_statement,
- to_compare_dst_db_create_statement))
- raise db_errors.OSArchiverNotEqualDbCreateStatements
- else:
- logging.debug("'%s' on remote DB does not exists",
- self.archive_db_name)
- sql = re.sub('`{db}`'.format(db=database),
- '`{db}`'.format(db=self.archive_db_name),
- src_db_create_statement)
- self.db_request(sql=sql)
- if not self.dry_run:
- logging.debug("Successfully created '%s'",
- self.archive_db_name)
|