Skip to content

Commit

Permalink
Merge pull request #1 from UniversityOfHelsinkiCS/improvement/create-…
Browse files Browse the repository at this point in the history
…test-db-on-startup

modified docker-compose file to create testdb on startup
  • Loading branch information
jleh authored Nov 30, 2018
2 parents c2517d8 + 28f8f93 commit 8b8c6c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ services:
- "5421:5432"
volumes:
- ./pgdata:/var/lib/postgresql/data
- ./scripts/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:ro
container_name: oodi_db
environment:
POSTGRES_DB: tkt_oodi
- POSTGRES_MULTIPLE_DATABASES=tkt_oodi,tkt_oodi_test
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=
redis:
image: redis
command: ["redis-server", "--appendonly", "yes"]
Expand Down Expand Up @@ -72,4 +75,4 @@ services:
environment:
- ENV=development
- MONGO_URI=mongodb://mongo_db:27017/oodilearn
container_name: oodilearn
container_name: oodilearn
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

0 comments on commit 8b8c6c5

Please sign in to comment.