Skip to content

Commit 82ee491

Browse files
authored
Fix alter table add key exception (#153)
1 parent 02f2302 commit 82ee491

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

mysql_ch_replicator/converter.py

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

584584
if op_name == 'add':
585-
if tokens[0].lower() in ('constraint', 'index', 'foreign', 'unique'):
585+
if tokens[0].lower() in ('constraint', 'index', 'foreign', 'unique', 'key'):
586586
continue
587587
self.__convert_alter_table_add_column(db_name, table_name, tokens)
588588
continue
589589

590590
if op_name == 'drop':
591-
if tokens[0].lower() in ('constraint', 'index', 'foreign', 'unique'):
591+
if tokens[0].lower() in ('constraint', 'index', 'foreign', 'unique', 'key'):
592592
continue
593593
self.__convert_alter_table_drop_column(db_name, table_name, tokens)
594594
continue

test_mysql_ch_replicator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,17 @@ def test_add_column_first_after_and_drop_column(monkeypatch):
14201420
assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="id=44")[0]['c1'] == 111)
14211421
assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="id=44")[0]['c2'] == 222)
14221422

1423+
# Test add KEY
1424+
mysql.execute(
1425+
f"ALTER TABLE `{TEST_TABLE_NAME}` ADD KEY `idx_c1_c2` (`c1`,`c2`)")
1426+
mysql.execute(
1427+
f"INSERT INTO `{TEST_TABLE_NAME}` (id, c1, c2) VALUES (46, 333, 444)",
1428+
commit=True,
1429+
)
1430+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, where="id=46")) == 1)
1431+
assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="id=46")[0]['c1'] == 333)
1432+
assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="id=46")[0]['c2'] == 444)
1433+
14231434
# Test drop column
14241435
mysql.execute(
14251436
f"ALTER TABLE `{TEST_TABLE_NAME}` DROP COLUMN c2")

0 commit comments

Comments
 (0)