Skip to content

Commit 154249a

Browse files
authored
Merge pull request laradock#1614 from ahkui/postgresql_init_db
add postgres init db
2 parents 5bffd43 + 7199ae5 commit 154249a

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ services:
322322
build: ./postgres
323323
volumes:
324324
- ${DATA_PATH_HOST}/postgres:/var/lib/postgresql/data
325+
- ${POSTGRES_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d
325326
ports:
326327
- "${POSTGRES_PORT}:5432"
327328
environment:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sh
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
#
3+
# Copy createdb.sh.example to createdb.sh
4+
# then uncomment then set database name and username to create you need databases
5+
#
6+
# example: .env POSTGRES_USER=appuser and need db name is myshop_db
7+
#
8+
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
9+
# CREATE USER myuser WITH PASSWORD 'mypassword';
10+
# CREATE DATABASE myshop_db;
11+
# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO myuser;
12+
# EOSQL
13+
#
14+
# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found.
15+
#
16+
17+
set -e
18+
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
19+
# CREATE USER db1 WITH PASSWORD 'db1';
20+
# CREATE DATABASE db1;
21+
# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1;
22+
# EOSQL
23+
24+
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
25+
# CREATE USER db2 WITH PASSWORD 'db2';
26+
# CREATE DATABASE db2;
27+
# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2;
28+
# EOSQL
29+
30+
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
31+
# CREATE USER db3 WITH PASSWORD 'db3';
32+
# CREATE DATABASE db3;
33+
# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3;
34+
# EOSQL

0 commit comments

Comments
 (0)