|
11 | 11 | from .mysql_api import MySQLApi |
12 | 12 | from .clickhouse_api import ClickhouseApi |
13 | 13 | from .converter import MysqlToClickhouseConverter, strip_sql_name, strip_sql_comments |
14 | | -from .table_structure import TableStructure |
| 14 | +from .table_structure import TableStructure, TableField |
15 | 15 | from .binlog_replicator import DataReader, LogEvent, EventType |
16 | 16 | from .utils import GracefulKiller, touch_all_files |
17 | 17 |
|
@@ -147,6 +147,17 @@ def validate_database_settings(self): |
147 | 147 | 'Otherwise you will get DUPLICATES in your SELECT queries\n\n\n' |
148 | 148 | ) |
149 | 149 |
|
| 150 | + def validate_mysql_structure(self, mysql_structure: TableStructure): |
| 151 | + primary_field: TableField = mysql_structure.fields[mysql_structure.primary_key_idx] |
| 152 | + if 'not null' not in primary_field.parameters.lower(): |
| 153 | + logger.warning('primary key validation failed') |
| 154 | + logger.warning( |
| 155 | + f'\n\n\n !!! WARNING - PRIMARY KEY NULLABLE (field "{primary_field.name}", table "{mysql_structure.table_name}") !!!\n\n' |
| 156 | + 'There could be errors replicating nullable primary key\n' |
| 157 | + 'Please ensure all tables has NOT NULL parameter for primary key\n' |
| 158 | + 'Or mark tables as skipped, see "exclude_tables" option\n\n\n' |
| 159 | + ) |
| 160 | + |
150 | 161 | def run(self): |
151 | 162 | try: |
152 | 163 | logger.info('launched db_replicator') |
@@ -199,6 +210,7 @@ def create_initial_structure_table(self, table_name): |
199 | 210 | mysql_structure = self.converter.parse_mysql_table_structure( |
200 | 211 | mysql_create_statement, required_table_name=table_name, |
201 | 212 | ) |
| 213 | + self.validate_mysql_structure(mysql_structure) |
202 | 214 | clickhouse_structure = self.converter.convert_table_structure(mysql_structure) |
203 | 215 | self.state.tables_structure[table_name] = (mysql_structure, clickhouse_structure) |
204 | 216 | self.clickhouse_api.create_table(clickhouse_structure) |
|
0 commit comments