dc5828dc5704dca4584c4c1539ebfc9ece065da0
[cacert-devel.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 schema_version ENGINE=INNODB;
62
63 echo "table schema_version altered to InnoDB"
64
65
66 ALTER TABLE abuserreports ENGINE=INNODB;
67
68 echo "table abusereports altered to InnoDB"
69
70
71 ALTER TABLE addlang ENGINE=INNODB;
72
73 echo "table addlang altered to InnoDB"
74
75
76 ALTER TABLE adminlog ENGINE=INNODB;
77
78 echo "table adminlog altered to InnoDB"
79
80
81 ALTER TABLE advertising ENGINE=INNODB;
82
83 echo "table advertising altered to InnoDB"
84
85
86 ALTER TABLE alerts ENGINE=INNODB;
87
88 echo "table alerts altered to InnoDB"
89
90
91 ALTER TABLE baddomains ENGINE=INNODB;
92
93 echo "table baddomains altered to InnoDB"
94
95
96 ALTER TABLE cats_passed ENGINE=INNODB;
97
98 echo "table cats_passed altered to InnoDB"
99
100
101 ALTER TABLE cats_type ENGINE=INNODB;
102
103 echo "table cats_type altered to InnoDB"
104
105
106 ALTER TABLE cats_variant ENGINE=INNODB;
107
108 echo "table cats_variant altered to InnoDB"
109
110
111 ALTER TABLE countries ENGINE=INNODB;
112
113 echo "table countries altered to InnoDB"
114
115
116 ALTER TABLE disputedomain ENGINE=INNODB;
117
118 echo "table disputedomain altered to InnoDB"
119
120
121 ALTER TABLE disputeemail ENGINE=INNODB;
122
123 echo "table disputeemail altered to InnoDB"
124
125
126 ALTER TABLE gpg ENGINE=INNODB;
127
128 echo "table gpg altered to InnoDB"
129
130
131 ALTER TABLE localias ENGINE=INNODB;
132
133 echo "table localias altered to InnoDB"
134
135
136 ALTER TABLE news ENGINE=INNODB;
137
138 echo "table news altered to InnoDB"
139
140
141 ALTER TABLE otphashes ENGINE=INNODB;
142
143 echo "table otphashes altered to InnoDB"
144
145
146 ALTER TABLE pinglog ENGINE=INNODB;
147
148 echo "table pinglog altered to InnoDB"
149
150
151 ALTER TABLE root_certs ENGINE=INNODB;
152
153 echo "table root_certs altered to InnoDB"
154
155
156 ALTER TABLE stampcache ENGINE=INNODB;
157
158 echo "table stampcache altered to InnoDB"
159
160
161 ALTER TABLE tickets ENGINE=INNODB;
162
163 echo "table tickets altered to InnoDB"
164
165
166 ALTER TABLE languages ENGINE=INNODB;
167
168 echo "table languages altered to InnoDB"
169
170
171 ALTER TABLE locations ENGINE=INNODB;
172
173 echo "table locations altered to InnoDB"
174
175
176 ALTER TABLE regions ENGINE=INNODB;
177
178 echo "table regions altered to InnoDB"
179
180
181 ALTER TABLE domaincerts ENGINE=INNODB;
182
183 echo "table domainderts altered to InnoDB"
184
185
186 ALTER TABLE domains ENGINE=INNODB;
187
188 echo "table domains altered to InnoDB"
189
190
191 ALTER TABLE domLink ENGINE=INNODB;
192
193 echo "table domLink altered to InnoDB"
194
195
196 ALTER TABLE emailcerts ENGINE=INNODB;
197
198 echo "table emailcerts altered to InnoDB"
199
200
201 ALTER TABLE emaillink ENGINE=INNODB;
202
203 echo "table emaillink altered to InnoDB"
204
205
206 ALTER TABLE email ENGINE=INNODB;
207
208 echo "table email altered to InnoDB"
209
210
211 ALTER TABLE notary ENGINE=INNODB;
212
213 echo "table notary altered to InnoDB"
214
215
216 ALTER TABLE tverify ENGINE=INNODB;
217
218 echo "table tverify altered to InnoDB"
219
220
221 ALTER TABLE tverify-vote ENGINE=INNODB;
222
223 echo "table tverify-vote altered to InnoDB"
224
225
226 ALTER TABLE userlocations ENGINE=INNODB;
227
228 echo "table userlocations altered to InnoDB"
229
230
231 ALTER TABLE users ENGINE=INNODB;
232
233 echo "table users altered to InnoDB"
234
235
236 ALTER TABLE user_agreements ENGINE=INNODB;
237
238 echo "table user_agreements altered to InnoDB"
239
240
241 ALTER TABLE orgdomaincerts ENGINE=INNODB;
242
243 echo "table orgdomaincerts altered to InnoDB"
244
245
246 ALTER TABLE orgdomains ENGINE=INNODB;
247
248 echo "table orgdomains altered to InnoDB"
249
250
251 ALTER TABLE orgdomlink ENGINE=INNODB;
252
253 echo "table orgdomlink altered to InnoDB"
254
255
256 ALTER TABLE orgemailcerts ENGINE=INNODB;
257
258 echo "table orgemailcerts altered to InnoDB"
259
260
261 ALTER TABLE orgemaillink ENGINE=INNODB;
262
263 echo "table orgemaillink altered to InnoDB"
264
265
266 ALTER TABLE orginfo ENGINE=INNODB;
267
268 echo "table orginfo altered to InnoDB"
269
270
271 ALTER TABLE org ENGINE=INNODB;
272
273 echo "table org altered to InnoDB"
274
275
276 ALTER TABLE statscache ENGINE=INNODB;
277
278 echo "table statscache altered to InnoDB"
279
280
281 -- Update schema version number
282 INSERT INTO `schema_version`
283 (`version`, `when`) VALUES
284 ('5' , NOW() );
285 SQL
286
287
288 echo "Database successfully migrated to version 5"
289 exit 0
290