Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add events migrations #40

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RABBIT_MESSENGER_TRANSPORT_DSN=amqp://guest:guest@rabbitmq:5672/%2f
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset=utf8"
POSTGRES_DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

# SCHEMA SCHEMA REGISTRY URL FOR AVRO SCHEMA REGISTRY
Expand All @@ -49,4 +49,5 @@ SCHEMA_REGISTRY_URL=schema-registry:8081
CLICKHOUSE_HOST=clickhouse
CLICKHOUSE_PORT=8123
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=
CLICKHOUSE_PASSWORD=
CLICKHOUSE_DATABASE=default
3 changes: 2 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RABBIT_MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f

###> doctrine/doctrine-bundle ###
# In development, it's common to use SQLite or PostgreSQL with a dev-specific database
DATABASE_URL="postgresql://user:password@localhost:5432/app_db_dev?serverVersion=16&charset=utf8"
POSTGRES_DATABASE_URL="postgresql://user:password@db:5432/app_db?serverVersion=16&charset=utf8"
# Alternatively, for SQLite:
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_dev.db"
###< doctrine/doctrine-bundle ###
Expand All @@ -31,3 +31,4 @@ CLICKHOUSE_HOST=clickhouse
CLICKHOUSE_PORT=8123
CLICKHOUSE_USERNAME=default
CLICKHOUSE_PASSWORD=
CLICKHOUSE_DATABASE=default
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
}
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^4.0",
"friendsofphp/php-cs-fixer": "^3.68.5",
"kwn/php-rdkafka-stubs": "^2.2.1",
"php-cs-fixer/shim": "^3.9.3",
Expand Down
171 changes: 170 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
ClickhouseMigrations\ClickhouseMigrationsBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
];
21 changes: 15 additions & 6 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
server_version: '16'
profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
connections:
postgres:
url: '%env(resolve:POSTGRES_DATABASE_URL)%'
charset: UTF8
default_table_options:
charset: UTF8
collate: UTF8_unicode_ci
clickhouse:
host: '%env(CLICKHOUSE_HOST)%'
port: '%env(CLICKHOUSE_PORT)%'
user: '%env(CLICKHOUSE_USERNAME)%'
password: '%env(CLICKHOUSE_PASSWORD)%'
dbname: '%env(CLICKHOUSE_DATABASE)%'
driver_class: FOD\DBALClickHouse\Driver
wrapper_class: FOD\DBALClickHouse\Connection
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
Expand Down
27 changes: 18 additions & 9 deletions src/Migrations/Clickhouse/Version20250207193422.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@ final class Version20250207193422 extends AbstractClickhouseMigration
public function up(Client $client): void
{
$client->write(
<<<CLICKHOUSE
CREATE TABLE IF NOT EXISTS events
(
id UUID,
event_name String,
event_data String,
created_at DateTime
<<<DANIEL
CREATE TABLE events (
id UUID PRIMARY KEY, -- Unique identifier for the event
event_name String, -- Name of the event (e.g., 'user_signup', 'order_created')
event_data String, -- Data related to the event in a serialized format (e.g., JSON)
created_at DateTime, -- Timestamp of when the event was created
updated_at DateTime DEFAULT now(), -- Timestamp of when the event was last updated
user_id UUID, -- Optional: The ID of the user associated with the event (if applicable)
event_type String, -- Optional: Type of the event (e.g., 'info', 'warning', 'error')
source String, -- Optional: The source of the event (e.g., 'web', 'mobile', 'api')
status String, -- Optional: Status of the event (e.g., 'pending', 'processed', 'failed')
processed_at DateTime, -- Optional: Timestamp of when the event was processed (if applicable)
priority INT, -- Optional: Priority level of the event (e.g., 1-5)
metadata String, -- Optional: Additional metadata related to the event (e.g., JSON)
is_archived Boolean DEFAULT false, -- Optional: Flag to mark events as archived
tags Array(String) -- Optional: Tags or categories for the event (e.g., ['user', 'login', 'success'])
)
ENGINE = MergeTree()
ORDER BY (created_at)
CLICKHOUSE,
ORDER BY (id, created_at)
DANIEL,
);
}
}
12 changes: 12 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
"src/Repository/.gitignore"
]
},
"doctrine/doctrine-fixtures-bundle": {
"version": "4.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "3.0",
"ref": "1f5514cfa15b947298df4d771e694e578d4c204d"
},
"files": [
"src/DataFixtures/AppFixtures.php"
]
},
"doctrine/doctrine-migrations-bundle": {
"version": "3.4",
"recipe": {
Expand Down