Last active
June 4, 2019 11:30
-
-
Save meysam81/3f60beaa4d5c74707405c47128d941ac to your computer and use it in GitHub Desktop.
multiple database for dockerized postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for database in $(echo "$POSTGRES_MULTIPLE_DATABASES" | tr ',' ' '); do | |
psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -h "$POSTGRES_HOST" <<EOSQL | |
CREATE USER "$database"; | |
CREATE DATABASE "$database"; | |
GRANT ALL PRIVILEGES ON DATABASE "$database" TO "$database"; | |
EOSQL | |
done | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postgres-migrate: | |
image: postgres:11.3 | |
container_name: name | |
hostname: name | |
volumes: | |
- "./postgres/init.sh:/init.sh" | |
command: bash /init.sh | |
restart: on-failure | |
environment: | |
POSTGRES_HOST: "host" | |
POSTGRES_USER: "user" | |
PGPASSWORD: "pass" | |
POSTGRES_MULTIPLE_DATABASES: comma_separated_dbs | |
depends_on: | |
- postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment