From 3ea756ae1bfdd35e5dcd2e0cccab45713feadfcc Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Sun, 19 Feb 2012 18:41:53 +0000 Subject: [PATCH] fix database upgrade path git-svn-id: http://www.observium.org/svn/observer/trunk@2879 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/sql-schema/update.php | 16 ++++++++++------ sql-schema/001.sql | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/includes/sql-schema/update.php b/includes/sql-schema/update.php index b619418019..8448d568be 100644 --- a/includes/sql-schema/update.php +++ b/includes/sql-schema/update.php @@ -29,13 +29,14 @@ if (!isset($debug)) } } +$insert = 0; + if ($db_rev = @dbFetchCell("SELECT version FROM `dbSchema`")) {} else { $db_rev = 0; + $insert = 1; } -$insert = 0; - # For transition from old system if ($old_rev = @dbFetchCell("SELECT revision FROM `dbSchema`")) { @@ -96,11 +97,14 @@ foreach ($filelist as $file) if (trim($line)) { if ($debug) { echo("$line \n"); } - $update = mysql_query($line); - if (!$update) + if ($line[0] != "#") { - $err++; - if ($debug) { echo(mysql_error() . "\n"); } + $update = mysql_query($line); + if (!$update) + { + $err++; + if ($debug) { echo(mysql_error() . "\n"); } + } } } } diff --git a/sql-schema/001.sql b/sql-schema/001.sql index bcfe46c8e6..d474142438 100644 --- a/sql-schema/001.sql +++ b/sql-schema/001.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS `alerts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `importance` int(11) NOT NULL DEFAULT '0', `device_id` int(11) NOT NULL, `message` text NOT NULL, `time_logged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `alerted` smallint(6) NOT NULL DEFAULT '0', KEY `id` (`id`) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `alerts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `importance` int(11) NOT NULL DEFAULT '0', `device_id` int(11) NOT NULL, `message` text NOT NULL, `time_logged` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `alerted` smallint(6) NOT NULL DEFAULT '0', KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `applications` ( `app_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `app_type` varchar(64) NOT NULL, PRIMARY KEY (`app_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `authlog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `user` text NOT NULL, `address` text NOT NULL, `result` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `bgpPeers` ( `bgpPeer_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `astext` varchar(64) NOT NULL, `bgpPeerIdentifier` text NOT NULL, `bgpPeerRemoteAs` int(11) NOT NULL, `bgpPeerState` text NOT NULL, `bgpPeerAdminStatus` text NOT NULL, `bgpLocalAddr` text NOT NULL, `bgpPeerRemoteAddr` text NOT NULL, `bgpPeerInUpdates` int(11) NOT NULL, `bgpPeerOutUpdates` int(11) NOT NULL, `bgpPeerInTotalMessages` int(11) NOT NULL, `bgpPeerOutTotalMessages` int(11) NOT NULL, `bgpPeerFsmEstablishedTime` int(11) NOT NULL, `bgpPeerInUpdateElapsedTime` int(11) NOT NULL, PRIMARY KEY (`bgpPeer_id`), KEY `device_id` (`device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;