This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathsetup.sh
executable file
·101 lines (87 loc) · 2.04 KB
/
setup.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
export DATABASE_SCHEMA_DIR=./schema
# we need to specify the database configuration for pop by sending additional parameter
# example: ./setup.sh create database.yml
create() {
if [ -z $1 ]; then
echo "database configuration cannot be empty"
exit 1;
fi
soda create -a --config $1
if [ $? -ne 0 ]; then
echo "failed to create database with config $1";
exit 1;
fi
}
# example: ./setup.sh drop database.yml
drop() {
if [ -z $1 ]; then
echo "database configuration cannot be empty"
exit 1;
fi
soda drop -a --config $1
if [ $? -ne 0 ]; then
echo "failed to drop database with config $1";
fi
}
# example: ./setup.sh generate user users
generate() {
if [ -z $1 ]; then
echo "database configuration cannot be empty"
exit 1;
fi
if [ -z $2 ]; then
echo "database name cannot be empty"
exit 1;
fi
if [ -z $3 ]; then
echo "migration name cannot be empty"
exit 1;
fi
cd ${SCRIPT_DIR}
soda generate sql -c $1 -e $2 -p ${DATABASE_SCHEMA_DIR}/$2 $3
if [ $? -ne 0 ]; then
echo "failed to generate new sql migration schema"
cd -
exit 1;
fi
cd -
}
migrate() {
if [ -z $1 ]; then
echo "database configuration cannot be empty"
exit 1;
fi
if [ -z $2 ]; then
echo "database name cannot be empty"
exit 1;
fi
if [ -z $3 ]; then
echo "migration type cannot be empty. must be up/down"
exit 1;
fi
cd ${SCRIPT_DIR}
soda migrate $3 -d -c $1 -e $2 -p ${DATABASE_SCHEMA_DIR}
if [ $? -ne 0 ]; then
echo "failed to generate new sql migration schema"
cd -
exit 1;
fi
cd -
}
# command for database setup
case $1 in
create)
create $2
;;
drop)
drop $2
;;
generate)
generate $2 $3 $4
;;
migrate)
migrate $2 $3 $4
;;
esac