Skip to content

Commit 08b906f

Browse files
committed
add copy_schema method for copying only the schema without data
1 parent 6da9bc6 commit 08b906f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pg_chameleon/lib/global_lib.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ def enable_replica(self):
314314
self.pg_engine.set_source_status("stopped")
315315
self.pg_engine.end_maintenance()
316316

317+
def copy_schema(self):
318+
"""
319+
The method calls init_replica adding a flag for skipping the data copy.
320+
Useful if we want to test for schema issues or to populate the schema preventively.
321+
322+
"""
323+
self.mysql_source.copy_table_data=False
324+
self.init_replica()
325+
317326
def init_replica(self):
318327
"""
319328
The method initialise a replica for a given source and configuration.
@@ -349,7 +358,7 @@ def __init_mysql_replica(self):
349358
foreground = True
350359
else:
351360
foreground = False
352-
print("Init replica process for source %s started." % (self.args.source))
361+
print("Process for source %s started." % (self.args.source))
353362
keep_fds = [self.logger_fds]
354363
init_pid = os.path.expanduser('%s/%s.pid' % (self.config["pid_dir"],self.args.source))
355364
self.logger.info("Initialising the replica for source %s" % self.args.source)
@@ -369,7 +378,7 @@ def __init_pgsql_replica(self):
369378
foreground = True
370379
else:
371380
foreground = False
372-
print("Init replica process for source %s started." % (self.args.source))
381+
print("Process for source %s started." % (self.args.source))
373382
keep_fds = [self.logger_fds]
374383
init_pid = os.path.expanduser('%s/%s.pid' % (self.config["pid_dir"],self.args.source))
375384
self.logger.info("Initialising the replica for source %s" % self.args.source)

pg_chameleon/lib/mysql_lib.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self):
2727
self.schema_only = {}
2828
self.gtid_mode = False
2929
self.gtid_enable = False
30+
self.copy_table_data = True
3031

3132

3233
def __del__(self):
@@ -546,6 +547,8 @@ def get_master_coordinates(self):
546547
:return: the master's log coordinates for the given table
547548
:rtype: dictionary
548549
"""
550+
if not self.conn_buffered.open:
551+
self.connect_db_buffered()
549552
sql_master = "SHOW MASTER STATUS;"
550553
self.cursor_buffered.execute(sql_master)
551554
master_status = self.cursor_buffered.fetchall()
@@ -775,7 +778,11 @@ def __copy_tables(self):
775778
self.pg_engine.truncate_table(destination_schema,table)
776779
master_status = self.copy_data(schema, table)
777780
else:
778-
master_status = self.copy_data(schema, table)
781+
if self.copy_table_data:
782+
master_status = self.copy_data(schema, table)
783+
else:
784+
master_status = self.get_master_coordinates()
785+
779786
table_pkey = self.__create_indices(schema, table)
780787
self.pg_engine.store_table(destination_schema, table, table_pkey, master_status)
781788
if self.keep_existing_schema:

0 commit comments

Comments
 (0)