You've already forked postgres
mirror of
https://github.com/docker-library/postgres.git
synced 2025-07-28 10:42:06 +03:00
Merge pull request #801 from infosiftr/db-exists
Do not try to create databases that already exist
This commit is contained in:
@ -189,7 +189,13 @@ docker_process_sql() {
|
||||
# create initial database
|
||||
# uses environment variables for input: POSTGRES_DB
|
||||
docker_setup_db() {
|
||||
if [ "$POSTGRES_DB" != 'postgres' ]; then
|
||||
local dbAlreadyExists
|
||||
dbAlreadyExists="$(
|
||||
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" --tuples-only <<-'EOSQL'
|
||||
SELECT 1 FROM pg_database WHERE datname = :'db' ;
|
||||
EOSQL
|
||||
)"
|
||||
if [ -z "$dbAlreadyExists" ]; then
|
||||
POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL'
|
||||
CREATE DATABASE :"db" ;
|
||||
EOSQL
|
||||
|
Reference in New Issue
Block a user