Repository navigation
Expand file tree
/
Copy pathpc_db.sh
More file actions
executable file
·67 lines (62 loc) · 1.52 KB
/
Copy pathpc_db.sh
File metadata and controls
executable file
·67 lines (62 loc) · 1.52 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
#!/bin/bash
#
# pc_db.sh — manage the local pool_classifier Postgres container
#
# Usage:
# pc_db.sh up # start postgres (detached)
# pc_db.sh down # stop postgres
# pc_db.sh migrate # apply SQL migrations
# pc_db.sh init # up + migrate (one-step setup)
# pc_db.sh status # docker compose ps
# pc_db.sh logs # follow postgres logs
# pc_db.sh psql # interactive psql shell
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE_FILE="$SCRIPT_DIR/worker_health/pool_classifier_web/docker-compose.yml"
if [[ ! -f "$COMPOSE_FILE" ]]; then
echo "compose file not found: $COMPOSE_FILE" >&2
exit 1
fi
dc() {
docker compose -f "$COMPOSE_FILE" "$@"
}
cmd="${1:-}"
case "$cmd" in
up)
dc up -d postgres
;;
down)
dc down
;;
migrate)
dc run --rm migrate
;;
init)
dc up -d postgres
# Wait for the healthcheck to pass before running migrations.
for _ in {1..30}; do
status=$(docker inspect --format '{{.State.Health.Status}}' pool_classifier_web-postgres-1 2>/dev/null || echo "starting")
[[ "$status" == "healthy" ]] && break
sleep 1
done
dc run --rm migrate
;;
status|ps)
dc ps
;;
logs)
dc logs -f postgres
;;
psql)
docker exec -it pool_classifier_web-postgres-1 psql -U pc -d pool_classifier
;;
""|-h|--help|help)
sed -n '3,16p' "$0" | sed 's/^# \{0,1\}//'
;;
*)
echo "unknown command: $cmd" >&2
sed -n '3,16p' "$0" | sed 's/^# \{0,1\}//' >&2
exit 2
;;
esac