-
Notifications
You must be signed in to change notification settings - Fork 8
/
migrate.sh
executable file
·65 lines (57 loc) · 1.71 KB
/
migrate.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
#!/bin/sh
# Date: 02/11/24
# Author: Aaron Wu
# This aggergates all the necessary alembic migration commands
# Note: migration commands
# flask --app backend.api db init -d ./backend/api/migrations
# flask --app backend.api db stamp head -d ./backend/api/migrations
# flask --app backend.api db migrate -d ./backend/api/database/migrations
# flask --app backend.api db revision -d ./backend/api/database/migrations --autogenerate -m "updated db"
# flask --app backend.api db upgrade head -d ./backend/api/database/migrations
# flask --app backend.api db downgrade <version> -d ./backend/api/migrations
# flask --app backend.api db check -d ./backend/api/migrations
USAGE="script usage: $(basename $0) [-u] [-m <msg>] [-d <ver>] [-c] [-v] [-h]"
if (( $# == 0 )); then
echo $USAGE
exit 1
fi
while getopts 'um:d:chv' FLAG
do
case "$FLAG" in
u)
# upgrades to lastest alembic version
flask --app backend.api db upgrade head -d ./backend/api/migrations
;;
m)
# Migrate database
msg="$OPTARG"
# read -p "Enter migrate message: " msg;
flask --app backend.api db migrate -d ./backend/api/migrations -m "$msg";
flask --app backend.api db upgrade head -d ./backend/api/migrations
;;
d)
# Downgrade to another alembic version
ver="$OPTARG"
# read -p "Enter downgrade version: " ver;
flask --app backend.api db downgrade $ver -d ./backend/api/migrations
;;
c)
# Checks if database needs migration
flask --app backend.api db check -d ./backend/api/migrations
;;
h)
# Usage help
echo $USAGE >&2
exit 1
;;
v)
# Version
flask --app backend.api db current -d ./backend/api/migrations
;;
?)
# Invalid flag
echo $USAGE >&2
exit 1
;;
esac
done