1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- def create_archive_table(self, database=None, table=None):
- """
- Create the archive table in the archive database.
- It checks that Source and Destination table are the identical.
- """
- # Call create db if archive_db_name is None
- if self.archive_db_name is None:
- self.create_archive_db(database=database)
- else:
- logging.debug("Archive db is '%s'", self.archive_db_name)
- # Check if table exists
- archive_table_exists = False
- if self.archive_db_exists:
- archive_table_exists = self.archive_table_exists(database=database,
- table=table)
- # retrieve source tabe create statement
- # if archive table exists, compare create statement
- # else use the statement to create it
- src_create_table_statement = self.get_src_create_table_statement(
- database=database, table=table)
- if archive_table_exists:
- logging.debug("Remote DB has '%s.%s' table", self.archive_db_name,
- self.archive_table_name)
- dst_table_create_statement = self.get_dst_create_table_statement(
- database=self.archive_db_name, table=self.archive_table_name)
- self.compare_src_and_dst_create_table_statement(
- src_statement=src_create_table_statement,
- dst_statement=dst_table_create_statement,
- src_table=table,
- dst_table=self.archive_table_name)
- else:
- logging.debug("'%s' table on remote DB does not exists",
- self.archive_table_name)
- sql = re.sub(
- 'TABLE `{table}`'.format(table=table),
- 'TABLE `{table}`'.format(table=self.archive_table_name),
- src_create_table_statement)
- self.db_request(sql=sql,
- database=self.archive_db_name,
- foreign_key_check=False)
- if not self.dry_run:
- logging.debug("Successfully created '%s.%s'",
- self.archive_db_name, self.archive_table_name)
|