@@ -1057,6 +1057,47 @@ def test_string_primary_key(monkeypatch):
10571057 binlog_replicator_runner .stop ()
10581058
10591059
1060+ def test_if_exists_if_not_exists (monkeypatch ):
1061+ monkeypatch .setattr (DbReplicator , 'INITIAL_REPLICATION_BATCH_SIZE' , 1 )
1062+
1063+ cfg = config .Settings ()
1064+ cfg .load (CONFIG_FILE )
1065+
1066+ mysql = mysql_api .MySQLApi (
1067+ database = None ,
1068+ mysql_settings = cfg .mysql ,
1069+ )
1070+
1071+ ch = clickhouse_api .ClickhouseApi (
1072+ database = TEST_DB_NAME ,
1073+ clickhouse_settings = cfg .clickhouse ,
1074+ )
1075+
1076+ prepare_env (cfg , mysql , ch )
1077+
1078+ binlog_replicator_runner = BinlogReplicatorRunner ()
1079+ binlog_replicator_runner .run ()
1080+ db_replicator_runner = DbReplicatorRunner (TEST_DB_NAME )
1081+ db_replicator_runner .run ()
1082+
1083+ assert_wait (lambda : TEST_DB_NAME in ch .get_databases ())
1084+
1085+ mysql .execute (f"CREATE TABLE IF NOT EXISTS { TEST_DB_NAME } .{ TEST_TABLE_NAME } (id int NOT NULL, PRIMARY KEY(id));" )
1086+ mysql .execute (f"CREATE TABLE IF NOT EXISTS { TEST_TABLE_NAME } (id int NOT NULL, PRIMARY KEY(id));" )
1087+ mysql .execute (f"CREATE TABLE IF NOT EXISTS { TEST_DB_NAME } .{ TEST_TABLE_NAME_2 } (id int NOT NULL, PRIMARY KEY(id));" )
1088+ mysql .execute (f"CREATE TABLE IF NOT EXISTS { TEST_TABLE_NAME_2 } (id int NOT NULL, PRIMARY KEY(id));" )
1089+ mysql .execute (f"DROP TABLE IF EXISTS { TEST_DB_NAME } .{ TEST_TABLE_NAME } ;" )
1090+ mysql .execute (f"DROP TABLE IF EXISTS { TEST_TABLE_NAME } ;" )
1091+
1092+ ch .execute_command (f'USE { TEST_DB_NAME } ' )
1093+
1094+ assert_wait (lambda : TEST_TABLE_NAME_2 in ch .get_tables ())
1095+ assert_wait (lambda : TEST_TABLE_NAME not in ch .get_tables ())
1096+
1097+ db_replicator_runner .stop ()
1098+ binlog_replicator_runner .stop ()
1099+
1100+
10601101def test_parse_mysql_table_structure ():
10611102 query = "CREATE TABLE IF NOT EXISTS user_preferences_portal (\n \t \t \t id char(36) NOT NULL,\n \t \t \t category varchar(50) DEFAULT NULL,\n \t \t \t deleted tinyint(1) DEFAULT 0,\n \t \t \t date_entered datetime DEFAULT NULL,\n \t \t \t date_modified datetime DEFAULT NULL,\n \t \t \t assigned_user_id char(36) DEFAULT NULL,\n \t \t \t contents longtext DEFAULT NULL\n \t \t ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
10621103
@@ -1065,3 +1106,4 @@ def test_parse_mysql_table_structure():
10651106 structure = converter .parse_mysql_table_structure (query )
10661107
10671108 assert structure .table_name == 'user_preferences_portal'
1109+
0 commit comments