Skip to content

Commit 6c2576b

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

31 files changed

+658
-296
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
run: npm ci --prefer-offline
2222

2323
- name: Setup environment
24-
run: cp envs/.env.dev .env
24+
run: cp envs/.env.test .env
2525

2626
- name: Run tests
2727
run: npm test -- --coverage
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE IF NOT EXISTS gs_ch.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 gs_ch.event_props (
2+
event_id String,
3+
prop_key String,
4+
prop_value String
5+
) ENGINE = MergeTree()
6+
ORDER BY (event_id, prop_key);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
MIGRATIONS_DIR="/migrations"
4+
5+
echo "Starting migrations..."
6+
7+
for migration in $(ls ${MIGRATIONS_DIR}/*.sql | sort); do
8+
echo "Applying migration: $migration..."
9+
10+
if [ -z "$CLICKHOUSE_USER" ] && [ -z "$CLICKHOUSE_PASS" ]; then
11+
clickhouse-client --query="$(cat $migration)"
12+
else
13+
clickhouse-client --user="${CLICKHOUSE_USER}" --password="${CLICKHOUSE_PASS}" --query="$(cat $migration)"
14+
fi
15+
done
16+
17+
echo "Migrations complete!"

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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ 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
14+
15+
clickhouse-ui:
16+
image: ghcr.io/caioricciuti/ch-ui:latest
1217
depends_on:
13-
- db
18+
- clickhouse
19+
environment:
20+
- VITE_CLICKHOUSE_URL=http://localhost:${CLICKHOUSE_PORT}
21+
- VITE_CLICKHOUSE_USER=${CLICKHOUSE_USER}
22+
- VITE_CLICKHOUSE_PASS=${CLICKHOUSE_PASS}
23+
ports:
24+
- 5521:5521
25+

docker-compose.test.yml

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

32+
test-clickhouse:
33+
image: clickhouse/clickhouse-server:24-alpine
34+
entrypoint: ["/bin/sh", "-c"]
35+
command: |
36+
"/entrypoint.sh & \
37+
sleep 5 && \
38+
/migrations/run-migrations.sh && \
39+
wait"
40+
environment:
41+
CLICKHOUSE_DB: ${CLICKHOUSE_DB}
42+
restart: unless-stopped
43+
ports:
44+
- ${CLICKHOUSE_PORT}:8123
45+
volumes:
46+
- ./clickhouse/migrations:/migrations
47+
networks:
48+
- test-network
49+
3250
stripe-api:
3351
image: stripe/stripe-mock:latest-arm64
3452
ports:

docker-compose.yml

Lines changed: 22 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,25 @@ services:
2425
ports:
2526
- 6379:6379
2627

28+
clickhouse:
29+
image: clickhouse/clickhouse-server:24-alpine
30+
entrypoint: ["/bin/sh", "-c"]
31+
command: |
32+
"/entrypoint.sh & \
33+
sleep 5 && \
34+
/migrations/run-migrations.sh && \
35+
wait"
36+
environment:
37+
CLICKHOUSE_USER: ${CLICKHOUSE_USER}
38+
CLICKHOUSE_PASS: ${CLICKHOUSE_PASS}
39+
CLICKHOUSE_DB: ${CLICKHOUSE_DB}
40+
restart: unless-stopped
41+
ports:
42+
- ${CLICKHOUSE_PORT}:8123
43+
volumes:
44+
- clickhouse-data:/var/lib/clickhouse
45+
- ./clickhouse/migrations:/migrations
46+
2747
volumes:
2848
data:
49+
clickhouse-data:

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_PASS=password
16+
CLICKHOUSE_DB=gs_ch
17+
1218
DEMO_ORGANISATION_NAME=Talo Demo
1319

1420
SENDGRID_KEY=

envs/.env.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ DB_PORT=3307
33
DB_NAME=gs_test
44
DB_PASS=password
55

6+
CLICKHOUSE_HOST=127.0.0.1
7+
CLICKHOUSE_PORT=8124
8+
CLICKHOUSE_USER=
9+
CLICKHOUSE_PASS=
10+
CLICKHOUSE_DB=gs_ch
11+
612
SENDGRID_KEY=
713
SENTRY_DSN=
814

0 commit comments

Comments
 (0)