From 3110b7d115462fd9c25b1020becb989f8d83a306 Mon Sep 17 00:00:00 2001 From: Filipp Ozinov Date: Fri, 10 Oct 2025 12:01:36 +0400 Subject: [PATCH] Handle comment column name correctly --- mysql_ch_replicator/converter.py | 2 +- test_mysql_ch_replicator.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mysql_ch_replicator/converter.py b/mysql_ch_replicator/converter.py index 2df6781..382d7e6 100644 --- a/mysql_ch_replicator/converter.py +++ b/mysql_ch_replicator/converter.py @@ -1085,7 +1085,7 @@ def _strip_comments(self, create_statement): # Look for COMMENT keyword (case insensitive) if (i + 7 < len(create_statement) and create_statement[i:i+7].upper() == 'COMMENT' and - (i == 0 or not create_statement[i-1].isalnum()) and + (i == 0 or (not create_statement[i-1].isalnum() and create_statement[i-1] != '`')) and (i + 7 >= len(create_statement) or not create_statement[i+7].isalnum())): # Skip COMMENT keyword diff --git a/test_mysql_ch_replicator.py b/test_mysql_ch_replicator.py index c22e64d..353efd1 100644 --- a/test_mysql_ch_replicator.py +++ b/test_mysql_ch_replicator.py @@ -3314,6 +3314,21 @@ def test_charset_configuration(): "CREATE TABLE test (id int comment 'lowercase', name varchar(255) Comment 'Mixed case')", "CREATE TABLE test (id int , name varchar(255) )" ), + # Field named comment + ( + """CREATE TABLE test ( + `departments int(11) NOT NULL, + `termine int(11) NOT NULL, + `comment` varchar(120) DEFAULT NULL, + PRIMARY KEY (departments,termine) + )""", + """CREATE TABLE test ( + `departments int(11) NOT NULL, + `termine int(11) NOT NULL, + `comment` varchar(120) DEFAULT NULL, + PRIMARY KEY (departments,termine) + )""" + ), ]) def test_strip_comments_function(input_sql, expected_output): """