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