From 19a07cffc6b08e8109a6203d94b31e1037d97ed7 Mon Sep 17 00:00:00 2001 From: Stanislav Lysikov Date: Tue, 21 May 2024 16:06:54 +0300 Subject: [PATCH] bugfix: clickhouse change exception text in new version so we check table via system table --- Makefile | 5 ++ chmfc.py | 23 +++---- test-dockerfiles/docker-compose.ci.23.8.yml | 74 +++++++++++++++++++++ test-dockerfiles/docker-compose.yml | 4 +- utils/queries.py | 2 +- 5 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 test-dockerfiles/docker-compose.ci.23.8.yml diff --git a/Makefile b/Makefile index 3f79527..2ffe9f0 100644 --- a/Makefile +++ b/Makefile @@ -26,3 +26,8 @@ ci: docker compose -f test-dockerfiles/docker-compose.ci.yml down docker compose -f test-dockerfiles/docker-compose.ci.yml up --build chmfc docker compose -f test-dockerfiles/docker-compose.ci.yml down + + docker-compose -f test-dockerfiles/docker-compose.ci.23.8.yml rm -f + docker compose -f test-dockerfiles/docker-compose.ci.23.8.yml down + docker compose -f test-dockerfiles/docker-compose.ci.23.8.yml up --build chmfc + docker compose -f test-dockerfiles/docker-compose.ci.23.8.yml down diff --git a/chmfc.py b/chmfc.py index 423253e..3ef9dc7 100644 --- a/chmfc.py +++ b/chmfc.py @@ -25,22 +25,15 @@ def check_or_create_migrations_table(client: Client): # check migrations table and create it if needs - exists = True - try: - ch_client.execute(rule_queries.exists_migrations_table()) - except Exception as e: - if f"Table {migrations_table} doesn't exist" in str(e): - create_shards, create_distributed = rule_queries.create_migrations_table() - ch_client.execute(create_shards) - ch_client.execute(create_distributed) - - exists = False - logger.info(f"Table {migrations_table} has been created.") - else: - raise CHMFCBaseError(e) - - if exists: + migrations_tables_exists = ch_client.execute(rule_queries.exists_migrations_table()) + if migrations_tables_exists: logger.info(f"Table {migrations_table} exists.") + else: + create_shards, create_distributed = rule_queries.create_migrations_table() + ch_client.execute(create_shards) + ch_client.execute(create_distributed) + + logger.info(f"Table {migrations_table} has been created.") def handle_migration(client: Client, version: int, v: Migration): diff --git a/test-dockerfiles/docker-compose.ci.23.8.yml b/test-dockerfiles/docker-compose.ci.23.8.yml new file mode 100644 index 0000000..899c043 --- /dev/null +++ b/test-dockerfiles/docker-compose.ci.23.8.yml @@ -0,0 +1,74 @@ +version: '2.4' + +services: + + chmfc: + build: + context: ../ + dockerfile: Dockerfile + container_name: chmfc + environment: + CHMFC_CH_HOST: clickhouse + CHMFC_CH_LOGIN: test + CHMFC_CH_PASSWORD: test + CHMFC_CH_DATABASE: default + CHMFC_MIG_PATH: /migrations + CHMFC_MIG_TABLE: default.migrations + volumes: + - ../test-migrations:/migrations + depends_on: + clickhouse: + condition: service_healthy + clickhouse1: + condition: service_healthy + + clickhouse: + image: clickhouse/clickhouse-server:23.8 + container_name: test_clickhouse + volumes: + - ./clickhouse/macros.xml:/etc/clickhouse-server/conf.d/macros.xml + - ./clickhouse/zookeeper.xml:/etc/clickhouse-server/conf.d/zookeeper.xml + - ./clickhouse/remote_servers.xml:/etc/clickhouse-server/config.d/remote_servers.xml + environment: + CLICKHOUSE_DB: test + CLICKHOUSE_USER: test + CLICKHOUSE_PASSWORD: test + REPLICA_NAME: clickhouse + healthcheck: + test: ["CMD", "wget", "--spider", "-q", "http://localhost:8123/ping"] + interval: 5s + timeout: 3s + retries: 3 + depends_on: + zookeeper: + condition: service_started + + clickhouse1: + image: clickhouse/clickhouse-server:23.8 + container_name: test_clickhouse1 + volumes: + - ./clickhouse/macros.xml:/etc/clickhouse-server/conf.d/macros.xml + - ./clickhouse/zookeeper.xml:/etc/clickhouse-server/conf.d/zookeeper.xml + - ./clickhouse/remote_servers.xml:/etc/clickhouse-server/config.d/remote_servers.xml + environment: + CLICKHOUSE_DB: test + CLICKHOUSE_USER: test + CLICKHOUSE_PASSWORD: test + REPLICA_NAME: clickhouse1 + healthcheck: + test: ["CMD", "wget", "--spider", "-q", "http://localhost:8123/ping"] + interval: 5s + timeout: 3s + retries: 3 + depends_on: + zookeeper: + condition: service_started + + zookeeper: + image: zookeeper:3.5 + container_name: zookeeper + hostname: zookeeper + +networks: + default: + name: test diff --git a/test-dockerfiles/docker-compose.yml b/test-dockerfiles/docker-compose.yml index 14e1145..7f7163c 100644 --- a/test-dockerfiles/docker-compose.yml +++ b/test-dockerfiles/docker-compose.yml @@ -3,7 +3,7 @@ version: '2.4' services: clickhouse: - image: yandex/clickhouse-server:21.8.5.7 + image: clickhouse/clickhouse-server:23.8 container_name: test_clickhouse volumes: - ./clickhouse/macros.xml:/etc/clickhouse-server/conf.d/macros.xml @@ -24,7 +24,7 @@ services: condition: service_started clickhouse1: - image: yandex/clickhouse-server:21.8.5.7 + image: clickhouse/clickhouse-server:23.8 container_name: test_clickhouse1 volumes: - ./clickhouse/macros.xml:/etc/clickhouse-server/conf.d/macros.xml diff --git a/utils/queries.py b/utils/queries.py index d649fb4..c5feb27 100644 --- a/utils/queries.py +++ b/utils/queries.py @@ -5,7 +5,7 @@ def __init__(self, migrations_table: str): self.table = migrations_table.split('.')[1] def exists_migrations_table(self): - return f'select version from {self.migrations_table} limit 1' + return f"select uuid from system.tables where database = '{self.schema}' and name = '{self.table}'" def create_migrations_table(self): create_shards_query = '''