-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate-database.sh
executable file
·62 lines (48 loc) · 1.47 KB
/
migrate-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
#!/bin/bash
PRJPATH=$1
PRJPATH=${PRJPATH:-$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )}
read -p "Enter distribution type (typescript|javascript) [typescript]: " DISTRIBUTION_TYPE
DISTRIBUTION_TYPE=${DISTRIBUTION_TYPE:-typescript}
if [[ "$DISTRIBUTION_TYPE" != "typescript" && "$DISTRIBUTION_TYPE" != "javascript" ]]; then
echo "Invalid distribution type"
exit
fi
INITIALCOMMAND=''
if [[ "$DISTRIBUTION_TYPE" == "typescript" ]]; then
INITIALCOMMAND='node --experimental-modules --es-module-specifier-resolution=node --loader ts-node/esm ./database/migrate.ts --tablename '
elif [[ "$DISTRIBUTION_TYPE" == "javascript" ]]; then
INITIALCOMMAND='node --experimental-modules --es-module-specifier-resolution=node ./database/migrate.js --tablename '
fi
TABLENAME=''
read -p "Enter table to deploy (all|entity|job|user|token): " TABLE
if [[ "$TABLE" != "all" && "$TABLE" != "entity" && "$TABLE" != "job" && "$TABLE" != "user" && "$TABLE" != "token" ]]; then
echo "Invalid table"
exit
fi
case $TABLE in
entity)
TABLENAME='entity'
;;
job)
TABLENAME='job'
;;
user)
TABLENAME='user'
;;
token)
TABLENAME='token'
;;
all)
TABLENAME='all'
;;
*)
echo -n "Invalid table"
exit
;;
esac
COMMAND="$INITIALCOMMAND$TABLENAME"
if [[ "$DISTRIBUTION_TYPE" == "typescript" ]]; then
(cd "$PRJPATH" && eval "$COMMAND")
elif [[ "$DISTRIBUTION_TYPE" == "javascript" ]]; then
(cd "$PRJPATH"/dist && eval "$COMMAND")
fi