-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg-local
More file actions
executable file
·79 lines (75 loc) · 1.93 KB
/
pg-local
File metadata and controls
executable file
·79 lines (75 loc) · 1.93 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
display_help() {
echo "=================================================="
echo " Postgres Playround! "
echo "=================================================="
echo "Syntax: ./pg-local [command]"
echo
echo "---commands---"
echo "help Print CLI help"
echo "pull Pull the latest PostGres image from DockerHub"
echo "create Start up and expose the database!"
echo "start Run an instance you have stopped"
echo "stop Spin down the database"
echo "destroy Delete the DB container"
echo "prompt Start an interactive psql prompt in the container"
echo "execute Execute a sql file - must be in sql/ dir"
echo "dump Print out DDL for the default database"
echo
}
[ -f .env ] && source .env
export POSTGRES_USER=${POSTGRES_USER:-postgres}
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
export POSTGRES_DB=${POSTGRES_DB:-dev}
case "$1" in
pull)
docker pull postgres
;;
create)
docker run -d \
-p 5432:5432 \
--name pg-local \
-e POSTGRES_USER \
-e POSTGRES_PASSWORD \
-e POSTGRES_DB \
--volume "$PWD"/sql:/usr/src/sql \
--volume "$PWD"/data:/usr/src/data \
postgres
;;
start)
docker start pg-local
;;
stop)
docker stop pg-local
;;
destroy)
docker rm -f pg-local
;;
prompt)
docker exec -it pg-local \
psql \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}"
;;
execute)
docker exec -it pg-local \
psql \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
-f "/usr/src/sql/$2"
;;
dump)
docker exec -it pg-local \
pg_dump \
-U "${POSTGRES_USER}" \
-d "${POSTGRES_DB}" \
--schema-only
;;
help)
display_help
;;
*)
echo "No command specified, displaying help"
display_help
;;
esac