diff --git a/Dockerfile b/Dockerfile index ee9c3d0..acc88fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,2 @@ -FROM postgres:9.6 +FROM postgres:12.3 COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/ diff --git a/README.md b/README.md index 3db6ca3..11780e5 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ Clone the repository, mount its directory as a volume into - ../docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d environment: - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD= ### By building a custom image @@ -46,8 +44,6 @@ to the container: image: eu.gcr.io/your-project/postgres-multi-db environment: - POSTGRES_MULTIPLE_DATABASES=db1,db2 - - POSTGRES_USER=myapp - - POSTGRES_PASSWORD= ### Non-standard database names @@ -55,3 +51,9 @@ If you need to use non-standard database names (hyphens, uppercase letters etc), environment: - POSTGRES_MULTIPLE_DATABASES="test-db-1","test-db-2" + +### Things should be noted + +- All DB's will be under master user, if not mentioned it will be `postgres` +- You can not add `postgres` in the DB list, it's the default db. It will be create anyway. +- All DB's password will be same, if not mentioned it will be blank diff --git a/create-multiple-postgresql-databases.sh b/create-multiple-postgresql-databases.sh index aa665fa..bb718aa 100755 --- a/create-multiple-postgresql-databases.sh +++ b/create-multiple-postgresql-databases.sh @@ -7,9 +7,10 @@ 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; + GRANT ALL PRIVILEGES ON DATABASE $database TO $POSTGRES_USER; + \connect $database; + CREATE SCHEMA IF NOT EXISTS $DB_SCHEMA; EOSQL }