Skip to content

Commit f39fe91

Browse files
add clickhouse migrations and small example of migration
1 parent 447b149 commit f39fe91

File tree

9 files changed

+223
-18
lines changed

9 files changed

+223
-18
lines changed

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset
4545
# SCHEMA SCHEMA REGISTRY URL FOR AVRO SCHEMA REGISTRY
4646
# SCHEMA_REGISTRY_URL=http://localhost:8081
4747
SCHEMA_REGISTRY_URL=schema-registry:8081
48+
49+
CLICKHOUSE_HOST=clickhouse
50+
CLICKHOUSE_PORT=8123
51+
CLICKHOUSE_USERNAME=default
52+
CLICKHOUSE_PASSWORD=

.env.dev

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ DATABASE_URL="postgresql://user:password@localhost:5432/app_db_dev?serverVersion
2424
# Use a local schema registry for development
2525
SCHEMA_REGISTRY_URL=schema-registry:8081
2626
###< Avro Schema Registry ###
27+
28+
###> ClickHouse ###
29+
# Use a local ClickHouse for development
30+
CLICKHOUSE_HOST=clickhouse
31+
CLICKHOUSE_PORT=8123
32+
CLICKHOUSE_USERNAME=default
33+
CLICKHOUSE_PASSWORD=

clickhousetest.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"jobcloud/avro-validator": "^2.1",
2121
"jobcloud/php-kafka-lib": "^2.0",
2222
"league/csv": "^9.21.0",
23+
"mavlitov98/clickhouse-migrations": "^1.0",
2324
"php-amqplib/php-amqplib": "^3.7",
2425
"predis/predis": "^2.3",
2526
"promphp/prometheus_client_php": "^2.13.1",

composer.lock

Lines changed: 169 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
66
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
77
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
8+
ClickhouseMigrations\ClickhouseMigrationsBundle::class => ['all' => true],
89
];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
clickhouse_migrations:
2+
connection:
3+
host: '%env(CLICKHOUSE_HOST)%'
4+
port: '%env(CLICKHOUSE_PORT)%'
5+
username: '%env(CLICKHOUSE_USERNAME)%'
6+
password: '%env(CLICKHOUSE_PASSWORD)%'
7+
clickhouse_migrations_version_table: 'ch_migrations'
8+
clickhouse_migrations_path: '%kernel.project_dir%/src/Migrations/Clickhouse'
9+
clickhouse_migrations_namespace: 'App\Migrations\Clickhouse'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Migrations\Clickhouse;
6+
7+
use ClickHouseDB\Client;
8+
use ClickhouseMigrations\AbstractClickhouseMigration;
9+
10+
final class Version20250207193422 extends AbstractClickhouseMigration
11+
{
12+
public function up(Client $client): void
13+
{
14+
$client->write(
15+
<<<CLICKHOUSE
16+
CREATE TABLE IF NOT EXISTS events
17+
(
18+
id UUID,
19+
event_name String,
20+
event_data String,
21+
created_at DateTime
22+
)
23+
ENGINE = MergeTree()
24+
ORDER BY (created_at)
25+
CLICKHOUSE,
26+
);
27+
}
28+
}

symfony.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
".php-cs-fixer.dist.php"
4848
]
4949
},
50+
"mavlitov98/clickhouse-migrations": {
51+
"version": "v1.0.0"
52+
},
5053
"php-cs-fixer/shim": {
5154
"version": "3.9",
5255
"recipe": {

0 commit comments

Comments
 (0)