Skip to content

Commit

Permalink
add copy_schema method for copying only the schema without data
Browse files Browse the repository at this point in the history
  • Loading branch information
the4thdoctor committed Feb 11, 2022
1 parent 6da9bc6 commit 08b906f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pg_chameleon/lib/global_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ def enable_replica(self):
self.pg_engine.set_source_status("stopped")
self.pg_engine.end_maintenance()

def copy_schema(self):
"""
The method calls init_replica adding a flag for skipping the data copy.
Useful if we want to test for schema issues or to populate the schema preventively.
"""
self.mysql_source.copy_table_data=False
self.init_replica()

def init_replica(self):
"""
The method initialise a replica for a given source and configuration.
Expand Down Expand Up @@ -349,7 +358,7 @@ def __init_mysql_replica(self):
foreground = True
else:
foreground = False
print("Init replica process for source %s started." % (self.args.source))
print("Process for source %s started." % (self.args.source))
keep_fds = [self.logger_fds]
init_pid = os.path.expanduser('%s/%s.pid' % (self.config["pid_dir"],self.args.source))
self.logger.info("Initialising the replica for source %s" % self.args.source)
Expand All @@ -369,7 +378,7 @@ def __init_pgsql_replica(self):
foreground = True
else:
foreground = False
print("Init replica process for source %s started." % (self.args.source))
print("Process for source %s started." % (self.args.source))
keep_fds = [self.logger_fds]
init_pid = os.path.expanduser('%s/%s.pid' % (self.config["pid_dir"],self.args.source))
self.logger.info("Initialising the replica for source %s" % self.args.source)
Expand Down
9 changes: 8 additions & 1 deletion pg_chameleon/lib/mysql_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
self.schema_only = {}
self.gtid_mode = False
self.gtid_enable = False
self.copy_table_data = True


def __del__(self):
Expand Down Expand Up @@ -546,6 +547,8 @@ def get_master_coordinates(self):
:return: the master's log coordinates for the given table
:rtype: dictionary
"""
if not self.conn_buffered.open:
self.connect_db_buffered()
sql_master = "SHOW MASTER STATUS;"
self.cursor_buffered.execute(sql_master)
master_status = self.cursor_buffered.fetchall()
Expand Down Expand Up @@ -775,7 +778,11 @@ def __copy_tables(self):
self.pg_engine.truncate_table(destination_schema,table)
master_status = self.copy_data(schema, table)
else:
master_status = self.copy_data(schema, table)
if self.copy_table_data:
master_status = self.copy_data(schema, table)
else:
master_status = self.get_master_coordinates()

table_pkey = self.__create_indices(schema, table)
self.pg_engine.store_table(destination_schema, table, table_pkey, master_status)
if self.keep_existing_schema:
Expand Down

0 comments on commit 08b906f

Please sign in to comment.