summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINOPIAE <inopiae@cacert.org>2013-01-12 19:47:13 +0100
committerINOPIAE <inopiae@cacert.org>2013-01-12 19:47:13 +0100
commitf30e16840a42132874c942569285fd4c19580fe2 (patch)
treec2ce4662040ab75934b5e8bd9fd4f70665cd5dd4
parentb55acf1470bb4d174b8190fa560a6e4ca5ae3964 (diff)
downloadcacert-devel-f30e16840a42132874c942569285fd4c19580fe2.tar.gz
cacert-devel-f30e16840a42132874c942569285fd4c19580fe2.tar.xz
cacert-devel-f30e16840a42132874c942569285fd4c19580fe2.zip
bug 1135: split db change into to version3.sh fot the first step to change add the columns into Adminlog and create table OrgAdminlog. Second step clean up after software is changes in logging are added
-rw-r--r--scripts/db_migrations/version3.sh41
-rw-r--r--scripts/db_migrations/version4.sh96
2 files changed, 104 insertions, 33 deletions
diff --git a/scripts/db_migrations/version3.sh b/scripts/db_migrations/version3.sh
index c5b4b8c..2bf90e9 100644
--- a/scripts/db_migrations/version3.sh
+++ b/scripts/db_migrations/version3.sh
@@ -1,16 +1,16 @@
#!/bin/sh
# LibreSSL - CAcert web application
# Copyright (C) 2004-2011 CAcert Inc.
-#
+#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,7 +20,7 @@
# script to do database migrations
# This particular version migrates from the preversioned state to version 1
-# If you want to reuse it for further migrations you probably should pay special
+# If you want to reuse it for further migrations you probably should pay special
# attention because you have to adjust it a bit
set -e # script fails if any command fails
@@ -53,46 +53,21 @@ SQL
if [ $schema_version != 2 ]; then
cat >&$STDERR <<- ERROR
Error: database schema is not in the right version to do the migration!
- Expected version: 1 (i.e. the version before there was versioning)
+ Expected version: 2 (i.e. the version before there was versioning)
ERROR
exit 2
fi
mysql $mysql_opt <<- 'SQL'
--- dump table AdminLog
-SELECT *
- INTO OUTFILE "???"
- FIELDS TERMINATED BY ','
- OPTIONALLY ENCLOSED BY '"'
- LINES TERMINATED BY "\n"
- FROM `adminlog`
- echo "Dump table create in ???"
-
-- alter table Admin log
-
-ALTER TABLE `adminlog` ADD `type` VARCHAR( 50 ) NOT NULL ,
- ADD `information` VARCHAR( 50 ) NOT NULL
-
--- update table admin log
-
-UPDATE `adminlog` SET `type` = 'old name or dob change',
-`information` = 'see dump ???'
-
--- alter table admin log
-
-ALTER TABLE `adminlog`
- DROP `old-lname`,
- DROP `old-dob`,
- DROP `new-lname`,
- DROP `new-dob`;
+ALTER TABLE `adminlog` ADD `type` VARCHAR( 50 ) NOT NULL ,
+ ADD `information` VARCHAR( 50 ) NOT NULL
-- create new table OrgAdminLog
-
-DROP TABLE IF EXISTS `orgadminlog`;
CREATE TABLE IF NOT EXISTS `orgadminlog` (
`when` datetime NOT NULL,
`oid` int(11) NOT NULL,
@@ -102,7 +77,7 @@ CREATE TABLE IF NOT EXISTS `orgadminlog` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-
+
-- Update schema version number
INSERT INTO `schema_version`
(`version`, `when`) VALUES
diff --git a/scripts/db_migrations/version4.sh b/scripts/db_migrations/version4.sh
new file mode 100644
index 0000000..8db7840
--- /dev/null
+++ b/scripts/db_migrations/version4.sh
@@ -0,0 +1,96 @@
+#!/bin/sh
+# LibreSSL - CAcert web application
+# Copyright (C) 2004-2011 CAcert Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+
+# script to do database migrations
+
+# This particular version migrates from the preversioned state to version 1
+# If you want to reuse it for further migrations you probably should pay special
+# attention because you have to adjust it a bit
+
+set -e # script fails if any command fails
+
+STDIN=0
+STDOUT=1
+STDERR=2
+
+if [ "$1" = "--help" ]; then
+ cat >&$STDERR <<- USAGE
+ Usage: $0 [MYSQL_OPTIONS]
+ You have to specify all options needed by "mysql" as if you had started
+ the MySQL command line client directly (including the name of the
+ database to operate on). The MySQL user used has to have enough
+ privileges to do all necessary operations (among others CREATE, ALTER,
+ DROP, UPDATE, INSERT, DELETE).
+ You might need to enter the mysql password multiple times if you
+ specify the -p option.
+ USAGE
+ exit 1
+fi
+
+mysql_opt=" --batch --skip-column-names $@"
+
+schema_version=$( mysql $mysql_opt <<- 'SQL'
+
+ SELECT MAX(`version`) FROM `schema_version`;
+SQL
+)
+if [ $schema_version != 3 ]; then
+ cat >&$STDERR <<- ERROR
+ Error: database schema is not in the right version to do the migration!
+ Expected version: 3 (i.e. the version before there was versioning)
+ ERROR
+ exit 2
+fi
+
+mysql $mysql_opt <<- 'SQL'
+
+-- dump table AdminLog
+SELECT *
+ INTO OUTFILE "???"
+ FIELDS TERMINATED BY ','
+ OPTIONALLY ENCLOSED BY '"'
+ LINES TERMINATED BY "\n"
+ FROM `adminlog`
+
+ echo "Dump table create in ???"
+
+-- update table admin log
+
+UPDATE `adminlog` SET `type` = 'old name or dob change',
+`information` = 'see dump ???'
+
+-- alter table admin log
+
+ALTER TABLE `adminlog`
+ DROP `old-lname`,
+ DROP `old-dob`,
+ DROP `new-lname`,
+ DROP `new-dob`;
+
+
+ -- Update schema version number
+ INSERT INTO `schema_version`
+ (`version`, `when`) VALUES
+ ('4' , NOW() );
+SQL
+
+
+echo "Database successfully migrated to version 4"
+exit 0
+