[icinga-checkins] icinga.org: icinga-core/test/ido: idoutils: upgradedb script for mysql installs all updates between $version and $currentrelease (Philipp Deneu) #2685

git at icinga.org git at icinga.org
Mon Aug 20 15:28:51 CEST 2012


Module: icinga-core
Branch: test/ido
Commit: 86db53de315443dd0423b3a11b00659342562711
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=86db53de315443dd0423b3a11b00659342562711

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Mon Aug 20 15:21:23 2012 +0200

idoutils: upgradedb script for mysql installs all updates between $version and $currentrelease (Philipp Deneu) #2685

refs #2685

---

 Changelog                               |    1 +
 THANKS                                  |    1 +
 module/idoutils/db/scripts/upgradedb.in |   36 ++++++++++++++++++++----------
 3 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/Changelog b/Changelog
index c87c178..949889f 100644
--- a/Changelog
+++ b/Changelog
@@ -42,6 +42,7 @@ ENHANCEMENTS
 * idoutils: change hasfunc to use sdbm algorithm for hashing precached objects #2792i - MF/GB
 * idoutils: add disable_notif_expire_time to programstatus table - #905 - MF
 * idoutils: add socket_perm to set unix socket permissions (Lennart Betz) #2659 - MF
+* idoutils: upgradedb script for mysql installs all updates between $version and $currentrelease (Philipp Deneu) #2685 - MF
 
 * install: add --with-mainurl to configure, allowing to set the main frame target url for index.html #2611 - MF
 * icinga.spec: use --with-mainurl to set the default to /icinga/cgi-bin/status.cgi?host=all&type=detail&servicestatustypes=29 #2611 - MF
diff --git a/THANKS b/THANKS
index dbb9c4d..bfa45ac 100644
--- a/THANKS
+++ b/THANKS
@@ -79,6 +79,7 @@ in various ways.  If we missed your name, let us know.
 * Jan David
 * Stephen Davies
 * Karl DeBisschop
+* Philipp Deneu
 * Tom De Blende
 * Mark DeTrano
 * Luca Di Stefano
diff --git a/module/idoutils/db/scripts/upgradedb.in b/module/idoutils/db/scripts/upgradedb.in
index 6bf1ea3..c1c6eaf 100755
--- a/module/idoutils/db/scripts/upgradedb.in
+++ b/module/idoutils/db/scripts/upgradedb.in
@@ -53,9 +53,8 @@ if ($@) {
 
 # Get current database version
 my $version;
-my $thisversion="1.7.0";
-my $lastversion="1.7.0";
-my $legacyversion="1.7.0";
+my $thisversion = "1.7.0";
+my $legacyversion = "1.7.0";
 
 $version = $dbh->selectrow_array("SELECT version FROM icinga_dbversion WHERE name='idoutils'");
 if ($version eq "") {
@@ -72,19 +71,32 @@ if ($version eq $thisversion){
     exit 0;
 }
 
-
 # Read upgrade script in the directory containing this script
 my $file="../mysql/upgrade/mysql-upgrade-$thisversion.sql";
 if (-e $file){
 	print "** DB upgrade required for $thisversion",$/;
-	print "     Using $file for upgrade...",$/;
-	my $p = "-p$password" if $password;	# Not required if password is blank
-	system("mysql -u $username $p -D$database -h$hostname < $file") == 0 or die "Upgrade from $file failed";
-	print "** Upgrade to $thisversion complete",$/;
-}
-else{
-	print "** No update script found for version $version - assuming none are required.",$/;
-	print "** Upgrade to $thisversion complete",$/;
+    while ($version lt $thisversion) {
+        opendir(UPGRADE, "../mysql/upgrade/") || die "Can not open upgrade directory";
+        our @a = readdir(UPGRADE);
+        @a = sort(@a);
+        foreach(@a) {
+            $_ =~ m/mysql-upgrade-(.*).sql/g;
+            my $upgradeversion = $1;
+            if ($upgradeversion ge $version){
+                my $file="../mysql/upgrade/mysql-upgrade-$upgradeversion.sql";
+                $version = $upgradeversion;
+                print "     Using $file for upgrade...",$/;
+                my $p = "-p$password" if $password;	# Not required if password is blank
+               	system("mysql -u $username $p -D$database -h$hostname < $file") == 0 or die "Upgrade from $file failed";
+                print "     Database version is now: $version",$/;
+            }
+        }
+        close UPGRADE;
+    }
+    print "** Upgrade to $thisversion complete",$/;
+} else{
+    print "** No update script found for version $version - assuming none are required.",$/;
+    print "** Upgrade to $thisversion complete",$/;
 }
 
 # from 1.3.0 on we do that manually in the upgrade sqls for each rdbms itsself





More information about the icinga-checkins mailing list