forked from liberapay/liberapay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recreate-schema.sh
executable file
·49 lines (39 loc) · 1.35 KB
/
recreate-schema.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
49
#!/bin/sh
# usage: DATABASE_URL=postgres://foo:bar@baz:5234/buz recreate-schema.sh
# Exit on errors and undefined variables
set -eu
alias psql='psql -v ON_ERROR_STOP=on'
if [ "${1-}" = "test" ]; then
psql $DATABASE_URL <<EOF
DO \$$
BEGIN
EXECUTE 'ALTER DATABASE '||current_database()||' SET synchronous_commit TO off';
END
\$$
EOF
fi
echo "=============================================================================="
echo "Applying sql/recreate-schema.sql ... "
echo
psql $DATABASE_URL < sql/recreate-schema.sql
echo "=============================================================================="
echo "Looking for sql/branch.sql ..."
echo
if [ -f sql/branch.sql ]
then psql $DATABASE_URL < sql/branch.sql
else
echo "None found. That's cool. You only need a sql/branch.sql file if you want to "
echo "include schema changes with your pull request."
fi
echo "=============================================================================="
echo "Applying sql/app-conf-defaults.sql ... "
echo
psql $DATABASE_URL < sql/app-conf-defaults.sql
if [ "${1-}" = "test" ]; then
echo "=============================================================================="
echo "Applying sql/app-conf-tests.sql ... "
echo
psql $DATABASE_URL < sql/app-conf-tests.sql
fi
echo
echo "=============================================================================="