Skip to content

Commit 2315a38

Browse files
committed
Fix "CREATE TABLE IF NOT EXISTS"
1 parent 4186a90 commit 2315a38

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

mysql_ch_replicator/clickhouse_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
CREATE_TABLE_QUERY = '''
17-
CREATE TABLE {db_name}.{table_name}
17+
CREATE TABLE {if_not_exists} {db_name}.{table_name}
1818
(
1919
{fields},
2020
`_version` UInt64,
@@ -165,6 +165,7 @@ def create_table(self, structure: TableStructure, additional_indexes: list | Non
165165
primary_key = f'({primary_key})'
166166

167167
query = CREATE_TABLE_QUERY.format(**{
168+
'if_not_exists': 'IF NOT EXISTS' if structure.if_not_exists else '',
168169
'db_name': self.database,
169170
'table_name': structure.table_name,
170171
'fields': fields,

mysql_ch_replicator/converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def convert_field_type(self, mysql_type, mysql_parameters):
262262
def convert_table_structure(self, mysql_structure: TableStructure) -> TableStructure:
263263
clickhouse_structure = TableStructure()
264264
clickhouse_structure.table_name = mysql_structure.table_name
265+
clickhouse_structure.if_not_exists = mysql_structure.if_not_exists
265266
for field in mysql_structure.fields:
266267
clickhouse_field_type = self.convert_field_type(field.field_type, field.parameters)
267268
clickhouse_structure.fields.append(TableField(

0 commit comments

Comments
 (0)