forked from all-of-us/raw-data-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_database.sh
executable file
·71 lines (65 loc) · 1.82 KB
/
upgrade_database.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash -e
# Applies schema migrations found in alembic/versions to upgrade a database.
# A specific revision level can be provided, or if none is, all revisions will be applied (i.e.
# the schema of the database will be updated to the latest.)
#
USAGE="
Examples:
Upgrade the local development database:
tools/upgrade_database.sh [--revision <REVISION>]
Upgrade a deployed db from your development box:
tools/upgrade_database.sh --project all-or-us-rdr-staging \
--account [email protected] [--creds_account [email protected]]
Upgrade a deployed db from CircleCI:
tools/upgrade_database.sh --instance https://all-of-us-x.appspot.com --creds_file ~/creds_file.key
"
while true; do
case "$1" in
--revision) REVISION=$2; shift 2;;
--account) ACCOUNT=$2; shift 2;;
--creds_account) CREDS_ACCOUNT=$2; shift 2;;
--project) PROJECT=$2; shift 2;;
--instance) INSTANCE=$2; shift 2;;
-i) INSTANCE=$2; shift 2;;
--creds_file) CREDS_FILE=$2; shift 2;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ "${PROJECT}" ]
then
if [ -z "${ACCOUNT}" ]
then
echo "--account must be specified with --project. $USAGE"
exit 1
fi
if [ -z "${CREDS_ACCOUNT}" ]
then
CREDS_ACCOUNT="${ACCOUNT}"
fi
elif [ "${INSTANCE}" ]
then
if [ -z "${CREDS_FILE}" ]
then
echo "--creds_file must be specified with --instance. $USAGE"
exit 1
fi
fi
if [ -z "${REVISION}" ]
then
REVISION=head
fi
if [ "${PROJECT}" -o "${INSTANCE}" ]
then
source tools/auth_setup.sh
run_cloud_sql_proxy
set_db_connection_string alembic
else
if [ -z ${DB_CONNECTION_STRING} ]
then
source tools/setup_local_vars.sh
set_local_db_connection_string alembic
fi
fi
# alembic.env.get_url() picks up DB_CONNECTION_STRING to find the db to upgrade.
(source tools/set_path.sh; alembic upgrade "${REVISION}")