forked from wassapaks/phalconphp-rest-jwt-acl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migratesql.sh
executable file
·58 lines (46 loc) · 1.21 KB
/
migratesql.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
bold=$(tput bold)
normal=$(tput sgr0)
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
printf "${RED}========================================================= \n"
printf "Bash Execute SQL Files \n"
printf "Author: Ef \n"
printf "Ver=0.1 \n"
printf "=========================================================${NC} \n"
FILES=dist/sql/*
function execute {
printf "=========================================================\n"
printf "${GREEN}${bold}Processing $3 file...${NC} \n"
printf " \n"
if mysql -u$1 -p$2 $4 < $3
then
printf "${GREEN}DONE!${NC} \n"
fi
printf "========================================================= \n"
# take action on each file. $f store current file name
}
function loopfiles {
FILES=dist/sql/*
for f in $FILES
do
if [ "$f" != "dist/sql/init.sql" ]
then
execute $1 $2 $f $3
fi
done
}
case "$3" in
migrate-sql)
execute $1 $2 dist/sql/init.sql $4
loopfiles $1 $2 $4
;;
init-only)
execute $1 $2 dist/sql/init.sql $4
;;
sql-commands-only)
loopfiles $1 $2 $4
;;
*) printf "No Sqlcommand \n"
;;
esac