@@ -205,7 +205,11 @@ def convert_alter_query(self, mysql_query, db_name):
205205 if op_name == 'alter' :
206206 continue
207207
208- raise Exception ('not implement' )
208+ if op_name == 'change' :
209+ self .__convert_alter_table_change_column (db_name , table_name , tokens )
210+ continue
211+
212+ raise Exception (f'operation { op_name } not implement, query: { subquery } ' )
209213
210214 def __convert_alter_table_add_column (self , db_name , table_name , tokens ):
211215 if len (tokens ) < 2 :
@@ -306,6 +310,51 @@ def __convert_alter_table_modify_column(self, db_name, table_name, tokens):
306310 if self .db_replicator :
307311 self .db_replicator .clickhouse_api .execute_command (query )
308312
313+ def __convert_alter_table_change_column (self , db_name , table_name , tokens ):
314+ if len (tokens ) < 3 :
315+ raise Exception ('wrong tokens count' , tokens )
316+
317+ if ',' in ' ' .join (tokens ):
318+ raise Exception ('add multiple columns not implemented' , tokens )
319+
320+ column_name = strip_sql_name (tokens [0 ])
321+ new_column_name = strip_sql_name (tokens [1 ])
322+ column_type_mysql = tokens [2 ]
323+ column_type_mysql_parameters = ' ' .join (tokens [3 :])
324+
325+ column_type_ch = self .convert_field_type (column_type_mysql , column_type_mysql_parameters )
326+
327+ # update table structure
328+ if self .db_replicator :
329+ table_structure = self .db_replicator .state .tables_structure [table_name ]
330+ mysql_table_structure : TableStructure = table_structure [0 ]
331+ ch_table_structure : TableStructure = table_structure [1 ]
332+
333+ current_column_type_ch = ch_table_structure .get_field (column_name ).field_type
334+
335+ if current_column_type_ch != column_type_ch :
336+
337+ mysql_table_structure .update_field (
338+ TableField (name = column_name , field_type = column_type_mysql ),
339+ )
340+
341+ ch_table_structure .update_field (
342+ TableField (name = column_name , field_type = column_type_ch ),
343+ )
344+
345+ query = f'ALTER TABLE { db_name } .{ table_name } MODIFY COLUMN { column_name } { column_type_ch } '
346+ self .db_replicator .clickhouse_api .execute_command (query )
347+
348+ if column_name != new_column_name :
349+ curr_field_mysql = mysql_table_structure .get_field (column_name )
350+ curr_field_clickhouse = ch_table_structure .get_field (column_name )
351+
352+ curr_field_mysql .name = new_column_name
353+ curr_field_clickhouse .name = new_column_name
354+
355+ query = f'ALTER TABLE { db_name } .{ table_name } RENAME COLUMN { column_name } TO { new_column_name } '
356+ self .db_replicator .clickhouse_api .execute_command (query )
357+
309358 def parse_create_table_query (self , mysql_query ) -> tuple :
310359 mysql_table_structure = self .parse_mysql_table_structure (mysql_query )
311360 ch_table_structure = self .convert_table_structure (mysql_table_structure )
0 commit comments