-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreset_databases.sh
executable file
·109 lines (88 loc) · 5.86 KB
/
reset_databases.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
102
103
104
105
106
107
108
109
#!/bin/bash
TYPE=""
DB="flourish"
if [ "$1" = "-t" ]; then
TYPE="$2"
shift 2
fi
if [ "$1" != "" ]; then
DB="$1"
fi
if [ "$TYPE" = "" ] || [ "$TYPE" = "db2" ]; then
if [ "$DB" = "flourish" ]; then
DB2_DB="flourish"
SCHEMA_REPLACE="flourish2"
else
DB2_DB=$(echo "$DB" | sed 's/ourish//')
SCHEMA_REPLACE="${DB2_DB}_2"
fi
db2batch -s off -time off -d fl -a $DB2_DB/password -f database/teardown-extended.db2.sql > /dev/null 2>&1
cp database/teardown-alternate_schema.db2.sql database/tmp.sql
sed -i -e "s/flourish2./$SCHEMA_REPLACE./g" database/tmp.sql
db2batch -s off -time off -d fl -a $DB2_DB/password -f database/tmp.sql > /dev/null 2>&1
db2batch -s off -time off -d fl -a $DB2_DB/password -f database/teardown.db2.sql > /dev/null 2>&1
db2batch -s off -time off -d fl -a $DB2_DB/password -f database/setup.db2.sql > /dev/null 2>&1
cp database/setup-alternate_schema.db2.sql database/tmp.sql
sed -i -e "s/flourish2./$SCHEMA_REPLACE./g" database/tmp.sql
db2batch -s off -time off -d fl -a $DB2_DB/password -f database/tmp.sql > /dev/null 2>&1
db2batch -s off -time off -d fl -a $DB2_DB/password -f database/setup-extended.db2.sql > /dev/null 2>&1
rm database/tmp.sql
fi
if [ "$TYPE" = "" ] || [ "$TYPE" = "mysql" ]; then
mysql -h db.flourishlib.com -u flourish --password=password $DB < database/teardown-extended.mysql.sql > /dev/null 2> /dev/null
mysql -h db.flourishlib.com -u flourish --password=password $DB < database/teardown.mysql.sql > /dev/null 2> /dev/null
mysql -h db.flourishlib.com -u flourish --password=password $DB < database/setup.mysql.sql > /dev/null 2> /dev/null
mysql -h db.flourishlib.com -u flourish --password=password $DB < database/setup-extended.mysql.sql > /dev/null 2> /dev/null
fi
if [ "$TYPE" = "" ] || [ "$TYPE" = "pgsql" ]; then
export PGPASSWORD="password"
psql -h db.flourishlib.com -U flourish -d $DB -f database/teardown-extended.postgresql.sql > /dev/null 2>&1
psql -h db.flourishlib.com -U flourish -d $DB -f database/teardown-alternate_schema.postgresql.sql > /dev/null 2>&1
psql -h db.flourishlib.com -U flourish -d $DB -f database/teardown.postgresql.sql > /dev/null 2>&1
psql -h db.flourishlib.com -U flourish -d $DB -f database/setup.postgresql.sql > /dev/null 2>&1
psql -h db.flourishlib.com -U flourish -d $DB -f database/setup-alternate_schema.postgresql.sql > /dev/null 2>&1
psql -h db.flourishlib.com -U flourish -d $DB -f database/setup-extended.postgresql.sql > /dev/null 2>&1
fi
if [ "$TYPE" = "" ] || [ "$TYPE" = "oracle" ]; then
if [ "$DB" = "flourish" ]; then
SCHEMA_REPLACE="flourish2"
ROLE_REPLACE="flourish2"
else
SCHEMA_REPLACE="${DB}_2"
ROLE_REPLACE="${DB}_role"
fi
echo "exit" | sqlplus -S $DB/password@db.flourishlib.com/XE "@database/teardown-extended.oracle.sql" > /dev/null
cp database/teardown-alternate_schema.oracle.sql database/tmp.sql
sed -i -e "s/flourish2./$SCHEMA_REPLACE./g" -e "s/flourish_role/$ROLE_REPLACE/g" database/tmp.sql
echo "exit" | sqlplus -S $DB/password@db.flourishlib.com/XE "@database/tmp.sql" > /dev/null
echo "exit" | sqlplus -S $DB/password@db.flourishlib.com/XE "@database/teardown.oracle.sql" > /dev/null
cp database/setup.oracle.sql database/tmp.sql
sed -i -e "s/\\\\;/;/g" -e 's/^;/\//' database/tmp.sql
echo "exit" | sqlplus -S $DB/password@db.flourishlib.com/XE "@database/tmp.sql" > /dev/null
cp database/setup-alternate_schema.oracle.sql database/tmp.sql
sed -i -e "s/flourish2./$SCHEMA_REPLACE./g" -e "s/flourish_role/$ROLE_REPLACE/g" -e "s/\\\\;/;/g" -e 's/^;/\//' database/tmp.sql
echo "exit" | sqlplus -S $DB/password@db.flourishlib.com/XE "@database/tmp.sql" > /dev/null
cp database/setup-extended.oracle.sql database/tmp.sql
sed -i -e "s/\\\\;/;/g" -e 's/^;/\//' database/tmp.sql
echo "exit" | sqlplus -S $DB/password@db.flourishlib.com/XE "@database/tmp.sql" > /dev/null
rm database/tmp.sql
fi
if [ "$TYPE" = "" ] || [ "$TYPE" = "mssql" ]; then
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1122 -D $DB -L semicolon_hack=1 -i database/teardown-extended.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1122 -D $DB -L semicolon_hack=1 -i database/teardown-alternate_schema.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1122 -D $DB -L semicolon_hack=1 -i database/teardown.mssql.sql > /dev/null 2> /dev/null
if [[ $(uname -o) == Cygwin ]]; then
sed -r -i -e "s/(CREATE SCHEMA \w+;)/\1\nGO/g" database/setup-alternate_schema.mssql.sql > /dev/null 2> /dev/null
fi
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1122 -D $DB -L semicolon_hack=1 -i database/setup.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1122 -D $DB -L semicolon_hack=1 -i database/setup-alternate_schema.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1122 -D $DB -L semicolon_hack=1 -i database/setup-extended.mssql.sql > /dev/null 2> /dev/null
fi
if [ "$TYPE" = "" ] || [ "$TYPE" = "mssql2008" ]; then
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1123 -D $DB -L semicolon_hack=1 -i database/teardown-extended.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1123 -D $DB -L semicolon_hack=1 -i database/teardown-alternate_schema.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1123 -D $DB -L semicolon_hack=1 -i database/teardown.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1123 -D $DB -L semicolon_hack=1 -i database/setup.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1123 -D $DB -L semicolon_hack=1 -i database/setup-alternate_schema.mssql.sql > /dev/null 2> /dev/null
sqsh -U flourish -P "password" -S win-db.flourishlib.com:1123 -D $DB -L semicolon_hack=1 -i database/setup-extended.mssql.sql > /dev/null 2> /dev/null
fi