Skip to content

Commit

Permalink
Change: Only create new postgres db if doesn't exist yet in container
Browse files Browse the repository at this point in the history
Avoid errors when starting a container with an existing database.
  • Loading branch information
bjoernricks committed Jul 25, 2023
1 parent c16d41c commit b64e3fd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .docker/start-postgresql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ if [ -n "$POSTGRES_PASSWORD" ]; then
psql --host=/tmp -d postgres
fi

createdb --host=/tmp -O $POSTGRES_DB "$POSTGRES_USER"
DB_EXISTS="$(echo "SELECT 1 FROM pg_database WHERE datname = '$POSTGRES_DB';" | psql --host=/tmp -d postgres --tuples-only)"
if [ -z "$DB_EXISTS" ]; then
createdb --host=/tmp -O "$POSTGRES_DB" "$POSTGRES_USER"
fi;

psql --host=/tmp -d $POSTGRES_DB -c "create role dba with superuser noinherit;"
psql --host=/tmp -d $POSTGRES_DB -c "grant dba to $POSTGRES_USER;"
Expand Down

0 comments on commit b64e3fd

Please sign in to comment.