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

misc: Add config for a test database on API #283

Merged
merged 1 commit into from
Sep 22, 2023
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
4 changes: 3 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ services:
container_name: lago_db
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-lago}
POSTGRES_USER: ${POSTGRES_USER:-lago}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
PGDATA: /data/postgres
POSTGRES_MULTIPLE_DATABASES: lago,lago_test
volumes:
- ./pg-init-scripts:/docker-entrypoint-initdb.d
- postgres_data:/data/postgres
ports:
- 5432:5432
Expand Down Expand Up @@ -86,6 +87,7 @@ services:
environment:
- LAGO_API_URL=https://api.lago.dev
- DATABASE_URL=postgresql://${POSTGRES_USER:-lago}:${POSTGRES_PASSWORD:-changeme}@db:5432/${POSTGRES_DB:-lago}
- DATABASE_TEST_URL=postgresql://${POSTGRES_USER:-lago}:${POSTGRES_PASSWORD:-changeme}@db:5432/${POSTGRES_DB:-lago_test}
- REDIS_URL=redis://redis:6379
- SECRET_KEY_BASE=${SECRET_KEY_BASE:-your-secret-key-base-hex-64}
- LAGO_FRONT_URL=${FRONT_URL:-https://app.lago.dev}
Expand Down
22 changes: 22 additions & 0 deletions scripts/pg-init-scripts/create-multiple-postgresql-databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e
set -u

function create_user_and_database() {
local database=$1
echo " Creating user and database '$database'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER $database;
CREATE DATABASE $database;
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
EOSQL
}

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
create_user_and_database $db
done
echo "Multiple databases created"
fi