Skip to content

Commit caac6bf

Browse files
authored
Fix handling add unique index (#110)
1 parent 1be27cc commit caac6bf

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

mysql_ch_replicator/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ def convert_alter_query(self, mysql_query, db_name):
448448
tokens = tokens[1:]
449449

450450
if op_name == 'add':
451-
if tokens[0].lower() in ('constraint', 'index', 'foreign'):
451+
if tokens[0].lower() in ('constraint', 'index', 'foreign', 'unique'):
452452
continue
453453
self.__convert_alter_table_add_column(db_name, table_name, tokens)
454454
continue
455455

456456
if op_name == 'drop':
457-
if tokens[0].lower() in ('constraint', 'index', 'foreign'):
457+
if tokens[0].lower() in ('constraint', 'index', 'foreign', 'unique'):
458458
continue
459459
self.__convert_alter_table_drop_column(db_name, table_name, tokens)
460460
continue

test_mysql_ch_replicator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def test_e2e_regular(config_file):
137137
mysql.execute(f"ALTER TABLE `{TEST_TABLE_NAME}` ADD `last_name` varchar(255); ")
138138
mysql.execute(f"ALTER TABLE `{TEST_TABLE_NAME}` ADD `price` decimal(10,2) DEFAULT NULL; ")
139139

140+
mysql.execute(f"ALTER TABLE `{TEST_TABLE_NAME}` ADD UNIQUE INDEX prise_idx (price)")
141+
mysql.execute(f"ALTER TABLE `{TEST_TABLE_NAME}` DROP INDEX prise_idx, ADD UNIQUE INDEX age_idx (age)")
142+
140143
mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, age, last_name, price) VALUES ('Mary', 24, 'Smith', 3.2);", commit=True)
141144

142145
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 4)

0 commit comments

Comments
 (0)