-
Notifications
You must be signed in to change notification settings - Fork 0
/
rake-db-handle.sh
83 lines (76 loc) · 1.09 KB
/
rake-db-handle.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
#!/bin/bash
#Auteur : Florent Grognet
#Scirpt for an easier handling of ruby-on-rails : rake db:xx commands
#Constants
USAGE="${0##*/} -r -s -b -l \n
\t-r : database reset \n
\t-s : importing seeds \n
\t-b : bundle execution \n
\t-l : system rake use (/usr/bin/rake)
"
LRAKE="/usr/bin/rake"
RAKE="./bin/rake"
BUNDLE="bundle exec"
#Flags
r=0
s=0
b=0
l=0
#Set flags corresponding to arguments
while getopts ":rsbl" option
do
case $option in
r)
r=1
;;
s)
s=1
;;
b)
b=1
;;
l)
l=1
;;
\?)
echo -e $USAGE
exit 1
;;
esac
done
#Agruments control
if [ $r -eq 0 ]
then
if [ $s -eq 0 ]
then
echo -e $USAGE
exit 1
fi
fi
#Rake selection
if [ $l -eq 1 ]
then
$RAKE = $LRAKE
fi
#Database commands
if [ $b -eq 0 ]
then
if [ $r -eq 1 ]
then
$RAKE db:migrate:reset
fi
if [ $s -eq 1 ]
then
$RAKE db:seeds
fi
else
if [ $r -eq 1 ]
then
$BUNDLE $RAKE db:migrate:reset
fi
if [ $s -eq 1 ]
then
$BUNDLE $RAKE db:seeds
fi
fi
exit 0