65a03fa0e6974a1f8258a0934c362fd10d038c3a
[cacert-devel.git] / scripts / db_migrations / version2.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 # This particular version migrates from the preversioned state to version 1
23 # If you want to reuse it for further migrations you probably should pay special
24 # attention because you have to adjust it a bit
25
26 set -e # script fails if any command fails
27
28 STDIN=0
29 STDOUT=1
30 STDERR=2
31
32 if [ "$1" = "--help" ]; then
33 cat >&$STDERR <<- USAGE
34 Usage: $0 [MYSQL_OPTIONS]
35 You have to specify all options needed by "mysql" as if you had started
36 the MySQL command line client directly (including the name of the
37 database to operate on). The MySQL user used has to have enough
38 privileges to do all necessary operations (among others CREATE, ALTER,
39 DROP, UPDATE, INSERT, DELETE).
40 You might need to enter the mysql password multiple times if you
41 specify the -p option.
42 USAGE
43 exit 1
44 fi
45
46 mysql_opt=" --batch --skip-column-names $@"
47
48 schema_version=$( mysql $mysql_opt <<- 'SQL'
49
50 SELECT MAX(`version`) FROM `schema_version`;
51 SQL
52 )
53 if [ $schema_version != 1 ]; then
54 cat >&$STDERR <<- ERROR
55 Error: database schema is not in the right version to do the migration!
56 Expected version: 1 (i.e. the version before there was versioning)
57 ERROR
58 exit 2
59 fi
60
61 mysql $mysql_opt <<- 'SQL'
62
63 -- Organisation Assurance bug #1118
64 ALTER TABLE `orgemailcerts` ADD `ou` varchar(50) NOT NULL
65 DEFAULT '';
66
67
68 -- Bugs #855, #863, #864, #888, #1118
69 ALTER TABLE `notary`
70 -- add "TTP-Assisted" as method for point transfers (for TTP)
71 MODIFY `method`
72 enum(
73 'Face to Face Meeting',
74 'Trusted Third Parties',
75 'Thawte Points Transfer',
76 'Administrative Increase',
77 'CT Magazine - Germany',
78 'Temporary Increase',
79 'Unknown',
80 'TOPUP',
81 'TTP-Assisted'
82 ) NOT NULL DEFAULT 'Face to Face Meeting';
83
84
85 -- User table bug #1118
86 ALTER TABLE `users`
87 MODIFY `ttpadmin` tinyint(2) NOT NULL DEFAULT '0';
88
89
90 -- Update schema version number
91 INSERT INTO `schema_version`
92 (`version`, `when`) VALUES
93 ('2' , NOW() );
94 SQL
95
96
97 echo "Database successfully migrated to version 2"
98 exit 0
99