Skip to content

Commit

Permalink
bugfix: clickhouse change exception text in new version so we check t…
Browse files Browse the repository at this point in the history
…able via system table
  • Loading branch information
Stanislav Lysikov committed May 21, 2024
1 parent 20c68bf commit 19a07cf
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 8 additions & 15 deletions chmfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
74 changes: 74 additions & 0 deletions test-dockerfiles/docker-compose.ci.23.8.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test-dockerfiles/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '''
Expand Down

0 comments on commit 19a07cf

Please sign in to comment.