Skip to content

Commit 7ef3f87

Browse files
committed
migrate events from mysql to clickhouse
1 parent 6e2f5fc commit 7ef3f87

39 files changed

+756
-342
lines changed

clickhouse/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM clickhouse/clickhouse-server:24.6-alpine
2+
3+
RUN apk add --no-cache gettext
4+
5+
COPY /clickhouse/migrations /docker-entrypoint-initdb.d/
6+
COPY /clickhouse/entrypoint.sh /usr/local/bin/entrypoint.sh
7+
8+
RUN chmod +x /usr/local/bin/entrypoint.sh
9+
10+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

clickhouse/entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
INIT_DIR="/docker-entrypoint-initdb.d"
5+
FLAG_FILE="$INIT_DIR/.migrated"
6+
7+
if [ ! -f "$FLAG_FILE" ]; then
8+
for file in ${INIT_DIR}/*.sql; do
9+
if [ -f "$file" ]; then
10+
envsubst < "$file" > "$file.processed" && mv "$file.processed" "$file"
11+
echo "Processed migration $file"
12+
fi
13+
done
14+
15+
echo "Creating migrations lock"
16+
touch "$FLAG_FILE"
17+
else
18+
echo "Migrations lock set; Skipping envsubst processing"
19+
fi
20+
21+
exec /entrypoint.sh "$@"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE IF NOT EXISTS ${CLICKHOUSE_DB}.events
2+
(
3+
id String,
4+
name String,
5+
game_id UInt32,
6+
player_alias_id UInt32,
7+
dev_build Boolean,
8+
created_at DateTime,
9+
updated_at DateTime,
10+
PRIMARY KEY (id),
11+
INDEX name_idx (name) TYPE bloom_filter(0.01) GRANULARITY 64,
12+
INDEX game_id_idx (game_id) TYPE minmax GRANULARITY 64,
13+
INDEX player_alias_id_idx (player_alias_id) TYPE minmax GRANULARITY 64
14+
)
15+
ENGINE = MergeTree()
16+
ORDER BY (id, created_at, game_id, player_alias_id);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE IF NOT EXISTS ${CLICKHOUSE_DB}.event_props (
2+
event_id String,
3+
prop_key String,
4+
prop_value String
5+
) ENGINE = MergeTree()
6+
ORDER BY (event_id, prop_key);

docker-compose.ci.yml

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,9 @@
11
services:
2-
test-db:
3-
image: mysql:8.4
4-
command: --mysql-native-password=ON
5-
environment:
6-
- MYSQL_DATABASE=${DB_NAME}
7-
- MYSQL_ROOT_PASSWORD=${DB_PASS}
8-
restart: always
9-
healthcheck:
10-
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
11-
interval: 2s
12-
timeout: 2s
13-
retries: 10
14-
ports:
15-
- ${DB_PORT}:3306
16-
volumes:
17-
- test-data:/var/lib/mysql
18-
networks:
19-
- test-network
20-
212
test-redis:
223
image: bitnami/redis:7.2
4+
command:
235
environment:
246
- REDIS_PASSWORD=${REDIS_PASSWORD}
25-
ports:
26-
- ${REDIS_PORT}:6379
27-
depends_on:
28-
test-db:
29-
condition: service_healthy
30-
networks:
31-
- test-network
327

338
stripe-api:
349
image: stripe/stripe-mock:latest
35-
ports:
36-
- 12111:12111
37-
- 12112:12112
38-
networks:
39-
- test-network
40-
41-
volumes:
42-
test-data:
43-
44-
networks:
45-
test-network:

docker-compose.dev.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ services:
44
context: .
55
target: dev
66
image: backend
7+
depends_on:
8+
- db
79
ports:
810
- 3000:80
911
volumes:
1012
- ./src:/usr/backend/src
1113
- ./tests:/usr/backend/tests
12-
depends_on:
13-
- db
14+

docker-compose.test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ services:
2929
networks:
3030
- test-network
3131

32+
test-clickhouse:
33+
build:
34+
context: .
35+
dockerfile: ./clickhouse/Dockerfile
36+
environment:
37+
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
38+
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
39+
CLICKHOUSE_DB: ${CLICKHOUSE_DB}
40+
restart: unless-stopped
41+
ports:
42+
- ${CLICKHOUSE_PORT}:8123
43+
networks:
44+
- test-network
45+
3246
stripe-api:
3347
image: stripe/stripe-mock:latest-arm64
3448
ports:

docker-compose.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ services:
55
depends_on:
66
- db
77
- redis
8+
- clickhouse
89

910
db:
1011
image: mysql:8.4
1112
command: --mysql-native-password=ON
1213
environment:
1314
- MYSQL_DATABASE=${DB_NAME}
1415
- MYSQL_ROOT_PASSWORD=${DB_PASS}
15-
restart: always
16+
restart: unless-stopped
1617
ports:
1718
- 3306:3306
1819
volumes:
@@ -24,5 +25,20 @@ services:
2425
ports:
2526
- 6379:6379
2627

28+
clickhouse:
29+
build:
30+
context: .
31+
dockerfile: ./clickhouse/Dockerfile
32+
environment:
33+
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
34+
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
35+
CLICKHOUSE_DB: ${CLICKHOUSE_DB}
36+
restart: unless-stopped
37+
ports:
38+
- ${CLICKHOUSE_PORT}:8123
39+
volumes:
40+
- clickhouse-data:/var/lib/clickhouse
41+
2742
volumes:
2843
data:
44+
clickhouse-data:

envs/.dockerignore

Whitespace-only changes.

envs/.env.dev

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ DB_PASS=password
99

1010
REDIS_PASSWORD=password
1111

12+
CLICKHOUSE_HOST=clickhouse
13+
CLICKHOUSE_PORT=8123
14+
CLICKHOUSE_USER=gs_ch
15+
CLICKHOUSE_PASSWORD=password
16+
CLICKHOUSE_DB=gs_ch_dev
17+
1218
DEMO_ORGANISATION_NAME=Talo Demo
1319

1420
SENDGRID_KEY=

0 commit comments

Comments
 (0)