-
Notifications
You must be signed in to change notification settings - Fork 71
/
ingest.sh
48 lines (43 loc) · 1022 Bytes
/
ingest.sh
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
#!/usr/bin/env bash
display_usage() {
echo "Seed dev database with data from a pg_dump file."
echo
echo "Usage:"
echo " bash ingest.sh -f dump_file"
}
# Help
if [[ ( $1 == "--help") || ($1 == "-h")]]; then
display_usage
exit 0
fi
getopts ":f:" opt || true;
case $opt in
f)
if [ -f "$OPTARG" ]
then
FILE=$OPTARG
else
echo "Invalid path."
exit 1
fi
;;
\?)
# illegal option or argument
display_usage
exit 1
;;
:)
# -f present, but no path provided
echo "Please specify the path."
exit 1
;;
esac
if [[ $((OPTIND - $#)) -ne 1 ]]; then
# wrong number of args
display_usage
exit 1
fi
echo "Loading data from $FILE ..."
docker cp "$FILE" "$(docker compose ps -q db)":/tmp/data.dump
docker compose exec db pg_restore --username=perma --verbose --no-owner -h localhost -d perma /tmp/data.dump
docker compose exec db rm -f /tmp/data.dump