Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Release][release-image]][releases]
[![License][license-image]][license]

[release-image]: https://img.shields.io/badge/release-0.0.19-blue.svg?style=flat
[release-image]: https://img.shields.io/badge/release-0.0.20-blue.svg?style=flat
[releases]: https://github.com/bakwc/mysql_ch_replicator/releases

[license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat
Expand Down
46 changes: 46 additions & 0 deletions mysql_ch_replicator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@
from dataclasses import dataclass


def stype(obj):
return type(obj).__name__


@dataclass
class MysqlSettings:
host: str = 'localhost'
port: int = 3306
user: str = 'root'
password: str = ''

def validate(self):
if not isinstance(self.host, str):
raise ValueError(f'mysql host should be string and not {stype(self.host)}')

if not isinstance(self.port, int):
raise ValueError(f'mysql port should be int and not {stype(self.port)}')

if not isinstance(self.user, str):
raise ValueError(f'mysql user should be string and not {stype(self.user)}')

if not isinstance(self.password, str):
raise ValueError(f'mysql password should be string and not {stype(self.password)}')


@dataclass
class ClickhouseSettings:
Expand All @@ -19,12 +36,35 @@ class ClickhouseSettings:
user: str = 'root'
password: str = ''

def validate(self):
if not isinstance(self.host, str):
raise ValueError(f'clickhouse host should be string and not {stype(self.host)}')

if not isinstance(self.port, int):
raise ValueError(f'clickhouse port should be int and not {stype(self.port)}')

if not isinstance(self.user, str):
raise ValueError(f'clickhouse user should be string and not {stype(self.user)}')

if not isinstance(self.password, str):
raise ValueError(f'clickhouse password should be string and not {stype(self.password)}')


@dataclass
class BinlogReplicatorSettings:
data_dir: str = 'binlog'
records_per_file: int = 100000

def validate(self):
if not isinstance(self.data_dir, str):
raise ValueError(f'binlog_replicator data_dir should be string and not {stype(self.data_dir)}')

if not isinstance(self.records_per_file, int):
raise ValueError(f'binlog_replicator records_per_file should be int and not {stype(self.data_dir)}')

if self.records_per_file <= 0:
raise ValueError('binlog_replicator records_per_file should be positive')


class Settings:

Expand All @@ -48,6 +88,7 @@ def load(self, settings_file):
assert isinstance(self.databases, str) or isinstance(self.databases, list)
assert isinstance(self.tables, str) or isinstance(self.tables, list)
self.binlog_replicator = BinlogReplicatorSettings(**data['binlog_replicator'])
self.validate()

@classmethod
def is_pattern_matches(cls, substr, pattern):
Expand All @@ -67,3 +108,8 @@ def is_database_matches(self, db_name):

def is_table_matches(self, table_name):
return self.is_pattern_matches(table_name, self.tables)

def validate(self):
self.mysql.validate()
self.clickhouse.validate()
self.binlog_replicator.validate()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mysql-ch-replicator"
version = "0.0.19"
version = "0.0.20"
description = "Tool for replication of MySQL databases to ClickHouse"
authors = ["Filipp Ozinov <[email protected]>"]
license = "MIT"
Expand Down
Loading