-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_database.sh
More file actions
executable file
·29 lines (20 loc) · 932 Bytes
/
setup_database.sh
File metadata and controls
executable file
·29 lines (20 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
set -e
scripts_root=$(dirname "$0")
cd "$scripts_root"
cd ..
mkdir -p database/
# Create the PostgreSQL data.
initdb --username postgres --auth password --pwprompt --encoding utf8 --pgdata database/
# Start PostgreSQL database.
pg_ctl --pgdata database/ --log database/logfile.txt start
# Create 'debug' database and user for development and testing.
sql_create_db="CREATE DATABASE debug_db;"
sql_create_user="CREATE USER debug_user WITH ENCRYPTED PASSWORD 'debugdb123';"
sql_grant_priv="GRANT ALL PRIVILEGES ON DATABASE debug_db TO debug_user;"
psql --username postgres --command "$sql_create_db" --command "$sql_create_user" --command "$sql_grant_priv"
# Grant schema 'public' to the 'debug' user.
sql_grant_schema="GRANT ALL ON SCHEMA public TO debug_user;"
psql --username postgres --command "$sql_grant_schema" "debug_db"
# Stop PostgreSQL database.
pg_ctl --pgdata database/ --log database/logfile.txt stop