Source code taken from cacert-20141124.tar.bz2
[cacert.git] / scripts / db_migrations / version5.sh
1 #!/bin/sh
2 # LibreSSL - CAcert web application
3 # Copyright (C) 2004-2011 CAcert Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
19
20 # script to do database migrations
21
22 set -e # script fails if any command fails
23
24 STDIN=0
25 STDOUT=1
26 STDERR=2
27
28 if [ "$1" = "--help" ]; then
29 cat >&$STDERR <<- USAGE
30 Usage: $0 [MYSQL_OPTIONS]
31 You have to specify all options needed by "mysql" as if you had started
32 the MySQL command line client directly (including the name of the
33 database to operate on). The MySQL user used has to have enough
34 privileges to do all necessary operations (among others CREATE, ALTER,
35 DROP, UPDATE, INSERT, DELETE).
36 You might need to enter the mysql password multiple times if you
37 specify the -p option.
38 USAGE
39 exit 1
40 fi
41
42 mysql_opt=" --batch --skip-column-names $@"
43
44 schema_version=$( mysql $mysql_opt <<- 'SQL'
45
46 SELECT MAX(`version`) FROM `schema_version`;
47 SQL
48 )
49 if [ $schema_version != 4 ]; then
50 cat >&$STDERR <<- ERROR
51 Error: database schema is not in the right version to do the migration!
52 Expected version: 4
53 ERROR
54 exit 2
55 fi
56
57 mysql $mysql_opt <<- 'SQL'
58
59 -- Move myISAM to InnoDB bug #1172
60
61 ALTER TABLE `abusereports` ENGINE=INNODB;
62 system echo "table abusereports altered to InnoDB"
63
64
65 ALTER TABLE `addlang` ENGINE=INNODB;
66 system echo "table addlang altered to InnoDB"
67
68
69 ALTER TABLE `adminlog` ENGINE=INNODB;
70 system echo "table adminlog altered to InnoDB"
71
72
73 ALTER TABLE `advertising` ENGINE=INNODB;
74 system echo "table advertising altered to InnoDB"
75
76
77 ALTER TABLE `alerts` ENGINE=INNODB;
78 system echo "table alerts altered to InnoDB"
79
80
81 ALTER TABLE `baddomains` ENGINE=INNODB;
82 system echo "table baddomains altered to InnoDB"
83
84
85 ALTER TABLE `cats_passed` ENGINE=INNODB;
86 system echo "table cats_passed altered to InnoDB"
87
88
89 ALTER TABLE `cats_type` ENGINE=INNODB;
90 system echo "table cats_type altered to InnoDB"
91
92
93 ALTER TABLE `cats_variant` ENGINE=INNODB;
94 system echo "table cats_variant altered to InnoDB"
95
96
97 ALTER TABLE `countries` ENGINE=INNODB;
98 system echo "table countries altered to InnoDB"
99
100
101 ALTER TABLE `disputedomain` ENGINE=INNODB;
102 system echo "table disputedomain altered to InnoDB"
103
104
105 ALTER TABLE `disputeemail` ENGINE=INNODB;
106 system echo "table disputeemail altered to InnoDB"
107
108 ALTER TABLE `domaincerts` ENGINE=INNODB;
109 system echo "table domainderts altered to InnoDB"
110
111
112 ALTER TABLE `domains` ENGINE=INNODB;
113 system echo "table domains altered to InnoDB"
114
115
116 ALTER TABLE `domlink` ENGINE=INNODB;
117 system echo "table domlink altered to InnoDB"
118
119
120 ALTER TABLE `email` ENGINE=INNODB;
121 system echo "table email altered to InnoDB"
122
123
124 ALTER TABLE `emailcerts` ENGINE=INNODB;
125 system echo "table emailcerts altered to InnoDB"
126
127
128 ALTER TABLE `emaillink` ENGINE=INNODB;
129 system echo "table emaillink altered to InnoDB"
130
131
132 ALTER TABLE `gpg` ENGINE=INNODB;
133 system echo "table gpg altered to InnoDB"
134
135
136 ALTER TABLE `languages` ENGINE=INNODB;
137 system echo "table languages altered to InnoDB"
138
139
140 ALTER TABLE `localias` ENGINE=INNODB;
141 system echo "table localias altered to InnoDB"
142
143
144 ALTER TABLE `locations` ENGINE=INNODB;
145 system echo "table locations altered to InnoDB"
146
147
148 ALTER TABLE `news` ENGINE=INNODB;
149 system echo "table news altered to InnoDB"
150
151
152 ALTER TABLE `notary` ENGINE=INNODB;
153 system echo "table notary altered to InnoDB"
154
155
156 ALTER TABLE `org` ENGINE=INNODB;
157 system echo "table org altered to InnoDB"
158
159
160 ALTER TABLE `orgadminlog` ENGINE=INNODB;
161 system echo "table orgadminlog altered to InnoDB"
162
163
164 ALTER TABLE `orgdomaincerts` ENGINE=INNODB;
165 system echo "table orgdomaincerts altered to InnoDB"
166
167
168 ALTER TABLE `orgdomains` ENGINE=INNODB;
169 system echo "table orgdomains altered to InnoDB"
170
171
172 ALTER TABLE `orgdomlink` ENGINE=INNODB;
173 system echo "table orgdomlink altered to InnoDB"
174
175
176 ALTER TABLE `orgemailcerts` ENGINE=INNODB;
177 system echo "table orgemailcerts altered to InnoDB"
178
179
180 ALTER TABLE `orgemaillink` ENGINE=INNODB;
181 system echo "table orgemaillink altered to InnoDB"
182
183
184 ALTER TABLE `orginfo` ENGINE=INNODB;
185 system echo "table orginfo altered to InnoDB"
186
187
188 ALTER TABLE `otphashes` ENGINE=INNODB;
189 system echo "table otphashes altered to InnoDB"
190
191
192 ALTER TABLE `pinglog` ENGINE=INNODB;
193 system echo "table pinglog altered to InnoDB"
194
195
196 ALTER TABLE `regions` ENGINE=INNODB;
197 system echo "table regions altered to InnoDB"
198
199
200 ALTER TABLE `root_certs` ENGINE=INNODB;
201 system echo "table root_certs altered to InnoDB"
202
203
204 ALTER TABLE `schema_version` ENGINE=INNODB;
205 system echo "table schema_version altered to InnoDB"
206
207
208 ALTER TABLE `stampcache` ENGINE=INNODB;
209 system echo "table stampcache altered to InnoDB"
210
211
212 ALTER TABLE `statscache` ENGINE=INNODB;
213 system echo "table statscache altered to InnoDB"
214
215
216 ALTER TABLE `tickets` ENGINE=INNODB;
217 system echo "table tickets altered to InnoDB"
218
219
220 ALTER TABLE `tverify` ENGINE=INNODB;
221 system echo "table tverify altered to InnoDB"
222
223
224 ALTER TABLE `tverify-vote` ENGINE=INNODB;
225 system echo "table tverify-vote altered to InnoDB"
226
227
228 ALTER TABLE `user_agreements` ENGINE=INNODB;
229 system echo "table user_agreements altered to InnoDB"
230
231
232 ALTER TABLE `userlocations` ENGINE=INNODB;
233 system echo "table userlocations altered to InnoDB"
234
235
236 ALTER TABLE `users` ENGINE=INNODB;
237 system echo "table users altered to InnoDB"
238
239
240 -- Update schema version number
241 INSERT INTO `schema_version`
242 (`version`, `when`) VALUES
243 ('5' , NOW() );
244 SQL
245
246
247 echo "Database successfully migrated to version 5"
248 exit 0
249