Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion mysql_ch_replicator/db_replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .mysql_api import MySQLApi
from .clickhouse_api import ClickhouseApi
from .converter import MysqlToClickhouseConverter, strip_sql_name, strip_sql_comments
from .table_structure import TableStructure
from .table_structure import TableStructure, TableField
from .binlog_replicator import DataReader, LogEvent, EventType
from .utils import GracefulKiller, touch_all_files

Expand Down Expand Up @@ -147,6 +147,17 @@ def validate_database_settings(self):
'Otherwise you will get DUPLICATES in your SELECT queries\n\n\n'
)

def validate_mysql_structure(self, mysql_structure: TableStructure):
primary_field: TableField = mysql_structure.fields[mysql_structure.primary_key_idx]
if 'not null' not in primary_field.parameters.lower():
logger.warning('primary key validation failed')
logger.warning(
f'\n\n\n !!! WARNING - PRIMARY KEY NULLABLE (field "{primary_field.name}", table "{mysql_structure.table_name}") !!!\n\n'
'There could be errors replicating nullable primary key\n'
'Please ensure all tables has NOT NULL parameter for primary key\n'
'Or mark tables as skipped, see "exclude_tables" option\n\n\n'
)

def run(self):
try:
logger.info('launched db_replicator')
Expand Down Expand Up @@ -199,6 +210,7 @@ def create_initial_structure_table(self, table_name):
mysql_structure = self.converter.parse_mysql_table_structure(
mysql_create_statement, required_table_name=table_name,
)
self.validate_mysql_structure(mysql_structure)
clickhouse_structure = self.converter.convert_table_structure(mysql_structure)
self.state.tables_structure[table_name] = (mysql_structure, clickhouse_structure)
self.clickhouse_api.create_table(clickhouse_structure)
Expand Down
Loading