summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFelix Dörre <felix@dogcraft.de>2014-11-23 01:52:27 +0100
committerFelix Dörre <felix@dogcraft.de>2014-12-03 00:14:39 +0100
commit913751a5124106c879804adbc928ff766dcae0ad (patch)
tree059f562af504703defefd20b36e62138bb3372c9 /scripts
parent1cc5257aba1e6ae883caf464eaadf25783d2279d (diff)
downloadcacert-devel-913751a5124106c879804adbc928ff766dcae0ad.tar.gz
cacert-devel-913751a5124106c879804adbc928ff766dcae0ad.tar.xz
cacert-devel-913751a5124106c879804adbc928ff766dcae0ad.zip
bug-1341: add the db_migration script for the new column
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/db_migrations/version6.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/scripts/db_migrations/version6.sh b/scripts/db_migrations/version6.sh
new file mode 100755
index 0000000..dcba365
--- /dev/null
+++ b/scripts/db_migrations/version6.sh
@@ -0,0 +1,70 @@
+#!/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
+
+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 != 5 ]; then
+ cat >&$STDERR <<- ERROR
+ Error: database schema is not in the right version to do the migration!
+ Expected version: 5
+ ERROR
+ exit 2
+fi
+
+mysql $mysql_opt <<- 'SQL'
+ALTER TABLE `users` ADD `lastLoginAttempt` DATETIME NULL;
+system echo "added user column"
+
+ -- Update schema version number
+ INSERT INTO `schema_version`
+ (`version`, `when`) VALUES
+ ('6' , NOW() );
+SQL
+
+
+echo "Database successfully migrated to version 6"
+exit 0
+