Skip to content

Commit 67fd029

Browse files
committed
Fix index error #2
1 parent bbe94af commit 67fd029

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

mysql_ch_replicator/converter.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,20 @@ def get_db_and_table_name(self, token, db_name):
530530
table_name = token
531531
db_name = strip_sql_name(db_name)
532532
table_name = strip_sql_name(table_name)
533+
533534
if self.db_replicator:
534-
# Check if database and table match config BEFORE applying mapping
535-
matches_config = (
536-
self.db_replicator.config.is_database_matches(db_name)
537-
and self.db_replicator.config.is_table_matches(table_name))
535+
# If we're dealing with a relative table name (no DB prefix), we need to check
536+
# if the current db_name is already a target database name
537+
if '.' not in token and self.db_replicator.target_database == db_name:
538+
# This is a target database name, so for config matching we need to use the source database
539+
matches_config = (
540+
self.db_replicator.config.is_database_matches(self.db_replicator.database)
541+
and self.db_replicator.config.is_table_matches(table_name))
542+
else:
543+
# Normal case: check if source database and table match config
544+
matches_config = (
545+
self.db_replicator.config.is_database_matches(db_name)
546+
and self.db_replicator.config.is_table_matches(table_name))
538547

539548
# Apply database mapping AFTER checking matches_config
540549
if db_name == self.db_replicator.database:

test_mysql_ch_replicator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,9 @@ def test_schema_evolution_with_db_mapping():
22802280
clickhouse_settings=cfg.clickhouse,
22812281
)
22822282

2283+
ch.drop_database("mapped_target_db")
2284+
assert_wait(lambda: "mapped_target_db" not in ch.get_databases())
2285+
22832286
prepare_env(cfg, mysql, ch, db_name=TEST_DB_NAME)
22842287

22852288
# Create a test table with some columns using fully qualified name
@@ -2430,9 +2433,6 @@ def test_dynamic_column_addition_user_config():
24302433
# This would have caused an error before our fix
24312434
mysql.execute("UPDATE test_replication.replication_data SET val_2 = '100' WHERE code = 'test-1';", commit=True)
24322435

2433-
# Give some time for the replication to process the update
2434-
time.sleep(5)
2435-
24362436
# Verify replication processes are still running
24372437
binlog_pid = get_binlog_replicator_pid(cfg)
24382438
db_pid = get_db_replicator_pid(cfg, "test_replication")

0 commit comments

Comments
 (0)