laradock/postgres/docker-entrypoint-initdb.d/createdb.sh.example

35 lines
1.2 KiB
Plaintext
Raw Normal View History

2018-06-15 04:39:19 +08:00
#!/bin/bash
#
# Copy createdb.sh.example to createdb.sh
# then uncomment then set database name and username to create you need databases
#
# example: .env POSTGRES_USER=appuser and need db name is myshop_db
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
2018-06-15 15:30:45 +08:00
# CREATE USER my_user PASSWORD my_password;
2018-06-15 04:39:19 +08:00
# CREATE DATABASE myshop_db;
2018-06-15 15:30:45 +08:00
# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO my_user;
2018-06-15 04:39:19 +08:00
# EOSQL
#
# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found.
#
set -e
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
2018-06-15 15:27:37 +08:00
# CREATE USER db1 PASSWORD db1;
2018-06-15 04:39:19 +08:00
# CREATE DATABASE db1;
# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1;
# EOSQL
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
2018-06-15 15:27:37 +08:00
# CREATE USER db2 PASSWORD db2;
2018-06-15 04:39:19 +08:00
# CREATE DATABASE db2;
# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2;
# EOSQL
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
2018-06-15 15:27:37 +08:00
# CREATE USER db3 PASSWORD db3;
2018-06-15 04:39:19 +08:00
# CREATE DATABASE db3;
# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3;
# EOSQL