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

Added functionality to configure external databases for event storage #125

Merged
merged 1 commit into from
Apr 8, 2024
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
Added functionality to configure external databases for event storage
This commit introduces the ability to configure an external database for storing events. The configuration can be done via environment variables, allowing the use of different types of databases such as MongoDB, PostgreSQL, or MySQL.
  • Loading branch information
butschster committed Apr 8, 2024
commit 83f7d285bb30107092660de44660b7eb685535cd
15 changes: 15 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ CYCLE_SCHEMA_WARMUP=false
# Sentry
SENTRY_JS_SDK_URL=https://browser.sentry-cdn.com/7.69.0/bundle.tracing.replay.min.js
SENTRY_DSN_HOST=http:https://[email protected]:8082

# Persistence
PERSISTENCE_DRIVER=cache

# PERSISTENCE_DRIVER=database
DB_DRIVER=pgsql # mysql, pgsql
DB_DATABASE=buggregator
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=homestead
DB_PASSWORD=secret

# PERSISTENCE_DRIVER=mongodb
MONGODB_CONNECTION=mongodb:https://127.0.0.1:27017
MONGODB_DATABASE=buggregator
40 changes: 30 additions & 10 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

return [
'logger' => [
'default' => null,
'drivers' => [
// 'runtime' => 'stdout'
],
'default' => env('DB_LOGGER'),
'drivers' => [],
],

/**
Expand All @@ -27,7 +25,7 @@
*/
'databases' => [
'default' => [
'driver' => 'runtime',
'driver' => env('DB_DRIVER', 'pgsql'),
],
],

Expand All @@ -38,12 +36,34 @@
* the driver class and its connection options.
*/
'drivers' => [
'runtime' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\FileConnectionConfig(
database: '/dev/shm/buggregator'
'pgsql' => new Config\PostgresDriverConfig(
connection: new Config\Postgres\TcpConnectionConfig(
database: env('DB_DATABASE', 'buggregator'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 5432),
user: env('DB_USERNAME', 'postgres'),
password: env('DB_PASSWORD'),
),
schema: 'public',
queryCache: true,
options: [
'withDatetimeMicroseconds' => true,
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),
'mysql' => new Config\MySQLDriverConfig(
connection: new Config\MySQL\TcpConnectionConfig(
database: env('DB_DATABASE', 'buggregator'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 5432),
user: env('DB_USERNAME', 'postgres'),
password: env('DB_PASSWORD'),
),
queryCache: true
queryCache: true,
options: [
'withDatetimeMicroseconds' => true,
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),
// ...
],
];
2 changes: 1 addition & 1 deletion app/src/Application/Bootloader/PersistenceBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private function createRepository(
EnvironmentInterface $env
): EventRepositoryInterface {
return match ($env->get('PERSISTENCE_DRIVER', 'cache')) {
'cycle' => $factory->make(CycleOrmEventRepository::class),
'database' => $factory->make(CycleOrmEventRepository::class),
'mongodb' => $factory->make(MongoDBEventRepository::class),
'cache' => $factory->make(CacheEventRepository::class),
default => throw new \InvalidArgumentException('Unknown persistence driver'),
Expand Down
1 change: 0 additions & 1 deletion app/src/Application/Persistence/MongoDBEventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Application\Domain\Entity\Json;
use App\Application\Domain\ValueObjects\Uuid;
use Carbon\Carbon;
use Modules\Events\Domain\Event;
use Modules\Events\Domain\EventRepositoryInterface;
use MongoDB\Collection;
Expand Down
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ COPY --from=git /app /app
COPY --from=frontend /app /app/frontend
COPY --from=rr /usr/bin/rr /app
COPY --from=centrifugo /usr/local/bin/centrifugo /app/bin
COPY --from=git /app/docker/entrypoint.sh /app

ARG APP_VERSION=v1.0
ENV COMPOSER_ALLOW_SUPERUSER=1
Expand Down Expand Up @@ -65,4 +66,4 @@ LABEL org.opencontainers.image.source=$REPOSITORY
LABEL org.opencontainers.image.description="Buggregator"
LABEL org.opencontainers.image.licenses=MIT

CMD ./rr serve -c .rr-prod.yaml
CMD ["entrypoint.sh"]
7 changes: 7 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

php app.php configure
php app.php migrate --force

# serve server
./rr serve -c .rr-prod.yaml
Loading