Skip to content

Commit e804a14

Browse files
add events migrations
1 parent f39fe91 commit e804a14

File tree

8 files changed

+222
-19
lines changed

8 files changed

+222
-19
lines changed

.env

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ RABBIT_MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f
3939
#
4040
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
4141
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
42-
DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset=utf8"
42+
POSTGRES_DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset=utf8"
4343
###< doctrine/doctrine-bundle ###
4444

4545
# SCHEMA SCHEMA REGISTRY URL FOR AVRO SCHEMA REGISTRY
@@ -49,4 +49,5 @@ SCHEMA_REGISTRY_URL=schema-registry:8081
4949
CLICKHOUSE_HOST=clickhouse
5050
CLICKHOUSE_PORT=8123
5151
CLICKHOUSE_USERNAME=default
52-
CLICKHOUSE_PASSWORD=
52+
CLICKHOUSE_PASSWORD=
53+
CLICKHOUSE_DATABASE=default

.env.dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RABBIT_MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f
1515

1616
###> doctrine/doctrine-bundle ###
1717
# In development, it's common to use SQLite or PostgreSQL with a dev-specific database
18-
DATABASE_URL="postgresql://user:password@localhost:5432/app_db_dev?serverVersion=16&charset=utf8"
18+
POSTGRES_DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset=utf8"
1919
# Alternatively, for SQLite:
2020
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_dev.db"
2121
###< doctrine/doctrine-bundle ###
@@ -31,3 +31,4 @@ CLICKHOUSE_HOST=clickhouse
3131
CLICKHOUSE_PORT=8123
3232
CLICKHOUSE_USERNAME=default
3333
CLICKHOUSE_PASSWORD=
34+
CLICKHOUSE_DATABASE=default

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
}
9292
},
9393
"require-dev": {
94+
"doctrine/doctrine-fixtures-bundle": "^4.0",
9495
"friendsofphp/php-cs-fixer": "^3.68.5",
9596
"kwn/php-rdkafka-stubs": "^2.2.1",
9697
"php-cs-fixer/shim": "^3.9.3",

composer.lock

Lines changed: 170 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
@@ -6,4 +6,5 @@
66
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
77
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
88
ClickhouseMigrations\ClickhouseMigrationsBundle::class => ['all' => true],
9+
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
910
];

config/packages/doctrine.yaml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
doctrine:
22
dbal:
3-
url: '%env(resolve:DATABASE_URL)%'
4-
# IMPORTANT: You MUST configure your server version,
5-
# either here or in the DATABASE_URL env var (see .env file)
6-
server_version: '16'
7-
profiling_collect_backtrace: '%kernel.debug%'
8-
use_savepoints: true
3+
connections:
4+
postgres:
5+
url: '%env(resolve:POSTGRES_DATABASE_URL)%'
6+
charset: UTF8
7+
default_table_options:
8+
charset: UTF8
9+
collate: UTF8_unicode_ci
10+
clickhouse:
11+
host: '%env(CLICKHOUSE_HOST)%'
12+
port: '%env(CLICKHOUSE_PORT)%'
13+
user: '%env(CLICKHOUSE_USERNAME)%'
14+
password: '%env(CLICKHOUSE_PASSWORD)%'
15+
dbname: '%env(CLICKHOUSE_DATABASE)%'
16+
driver_class: FOD\DBALClickHouse\Driver
17+
wrapper_class: FOD\DBALClickHouse\Connection
918
orm:
1019
auto_generate_proxy_classes: true
1120
enable_lazy_ghost_objects: true

src/Migrations/Clickhouse/Version20250207193422.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ final class Version20250207193422 extends AbstractClickhouseMigration
1212
public function up(Client $client): void
1313
{
1414
$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
15+
<<<DANIEL
16+
CREATE TABLE events (
17+
id UUID PRIMARY KEY, -- Unique identifier for the event
18+
event_name String, -- Name of the event (e.g., 'user_signup', 'order_created')
19+
event_data String, -- Data related to the event in a serialized format (e.g., JSON)
20+
created_at DateTime, -- Timestamp of when the event was created
21+
updated_at DateTime DEFAULT now(), -- Timestamp of when the event was last updated
22+
user_id UUID, -- Optional: The ID of the user associated with the event (if applicable)
23+
event_type String, -- Optional: Type of the event (e.g., 'info', 'warning', 'error')
24+
source String, -- Optional: The source of the event (e.g., 'web', 'mobile', 'api')
25+
status String, -- Optional: Status of the event (e.g., 'pending', 'processed', 'failed')
26+
processed_at DateTime, -- Optional: Timestamp of when the event was processed (if applicable)
27+
priority INT, -- Optional: Priority level of the event (e.g., 1-5)
28+
metadata String, -- Optional: Additional metadata related to the event (e.g., JSON)
29+
is_archived Boolean DEFAULT false, -- Optional: Flag to mark events as archived
30+
tags Array(String) -- Optional: Tags or categories for the event (e.g., ['user', 'login', 'success'])
2231
)
2332
ENGINE = MergeTree()
24-
ORDER BY (created_at)
25-
CLICKHOUSE,
33+
ORDER BY (id, created_at)
34+
DANIEL,
2635
);
2736
}
2837
}

symfony.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
"src/Repository/.gitignore"
1414
]
1515
},
16+
"doctrine/doctrine-fixtures-bundle": {
17+
"version": "4.0",
18+
"recipe": {
19+
"repo": "github.com/symfony/recipes",
20+
"branch": "main",
21+
"version": "3.0",
22+
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
23+
},
24+
"files": [
25+
"src/DataFixtures/AppFixtures.php"
26+
]
27+
},
1628
"doctrine/doctrine-migrations-bundle": {
1729
"version": "3.4",
1830
"recipe": {

0 commit comments

Comments
 (0)