Skip to content

Commit

Permalink
Merge pull request #125 from buggregator/feature/external-database
Browse files Browse the repository at this point in the history
Added functionality to configure external databases for event storage
  • Loading branch information
butschster committed Apr 8, 2024
2 parents 4072c08 + 83f7d28 commit 6aa0365
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
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

0 comments on commit 6aa0365

Please sign in to comment.