Title: [opsview] [10569] merge in 10568 - convert to use bigints
Revision
10569
Author
aburzynski
Date
2012-10-22 15:48:32 +0100 (Mon, 22 Oct 2012)

Log Message

merge in 10568 - convert to use bigints

Modified Paths


Added Paths

Property Changed


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10560-10562,10565
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837
   + /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10560-10562,10565,10568
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837

Modified: trunk/opsview-core/bin/db_runtime
===================================================================
--- trunk/opsview-core/bin/db_runtime	2012-10-22 14:47:18 UTC (rev 10568)
+++ trunk/opsview-core/bin/db_runtime	2012-10-22 14:48:32 UTC (rev 10569)
@@ -67,7 +67,7 @@
 	INSERT nagios_database_version VALUES ('1.4b2');
 
 	CREATE TABLE snmptrapexceptions (
-		id int AUTO_INCREMENT,
+		id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
                 time varchar(16),	# This is a timev value
                 hostip varchar(16),
                 trapname varchar(128),
@@ -433,6 +433,7 @@
             ADD COLUMN eventtype SMALLINT DEFAULT 0 NOT NULL AFTER problem_has_been_acknowledged,
             ADD COLUMN host_state SMALLINT NOT NULL DEFAULT 0 AFTER eventtype,
             ADD COLUMN host_state_type SMALLINT NOT NULL DEFAULT 0 AFTER host_state;
+	ALTER TABLE nagios_hostchecks MODIFY COLUMN hostcheck_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
 
 
     # Add constraint to nagios_instances

Modified: trunk/opsview-core/installer/upgradedb_runtime.pl
===================================================================
--- trunk/opsview-core/installer/upgradedb_runtime.pl	2012-10-22 14:47:18 UTC (rev 10568)
+++ trunk/opsview-core/installer/upgradedb_runtime.pl	2012-10-22 14:48:32 UTC (rev 10569)
@@ -42,6 +42,7 @@
 use lib "$Bin/../lib", "$Bin/../etc";
 use Runtime;
 use Utils::DBVersion;
+use Opsview::Config;
 
 # Do not use Class::DBI methods to amend data
 
@@ -1349,6 +1350,33 @@
     $db->updated;
 }
 
+unless (
+    $db->is_installed(
+        "20121022bigints",
+        "Converting IDs to BIGINT (this could take some time)", "all"
+    )
+  )
+{
+    my %tables = (
+        nagios_hostchecks  => 'hostcheck_id',
+        snmptrapexceptions => 'id',
+    );
+
+    while ( my ( $table, $column ) = each %tables ) {
+        my $sth =
+          $dbh->column_info( undef, Opsview::Config->runtime_db, $table,
+            $column );
+        my $info = $sth->fetchrow_hashref || { TYPE_NAME => '' };
+        unless ( $info->{TYPE_NAME} eq 'BIGINT' ) {
+            $db->print( "Converting $table...\n" );
+            $dbh->do(
+                "ALTER TABLE $table MODIFY COLUMN $column BIGINT UNSIGNED NOT NULL AUTO_INCREMENT"
+            );
+        }
+    }
+    $db->updated;
+}
+
 if ( $db_changed || $db->changed || $nagios_db->changed ) {
     print "Finished updating database", $/;
 }

Copied: trunk/opsview-core/t/tests/Test/Opsview/Schema.pm (from rev 10568, branches/enterprise/DEV-professional/opsview-core/t/tests/Test/Opsview/Schema.pm)
===================================================================
--- trunk/opsview-core/t/tests/Test/Opsview/Schema.pm	                        (rev 0)
+++ trunk/opsview-core/t/tests/Test/Opsview/Schema.pm	2012-10-22 14:48:32 UTC (rev 10569)
@@ -0,0 +1,44 @@
+
+package Test::Opsview::Schema;
+
+use strict;
+use warnings;
+
+use base qw( Test::Opsview );
+
+use FindBin '$Bin';
+use lib "$Bin/../lib";
+use Test::More;
+
+sub _setup_testing : Test(setup => no_plan) {
+    my $self = shift;
+
+    # restore default test DB
+    $self->setup_db( qw( runtime ) );
+}
+
+sub bigints : Test(4) {
+    my $self = shift;
+
+    use_ok( 'Opsview::Snmptrapexception' );
+
+    my $bigint = '18446744073709551615';
+
+    my $create = Opsview::Snmptrapexception->insert(
+        {
+            id     => $bigint,
+            time   => time(),
+            hostip => '127.0.0.1',
+            reason => 'test',
+        }
+    );
+
+    my ($read) = Opsview::Snmptrapexception->search( id => $bigint );
+
+    is_deeply( $read, $create, 'Object created and retrieved correctly' );
+
+    is( $create->id, $bigint, 'Object with BIGINT id created correctly' );
+    is( $read->id,   $bigint, 'Object with BIGINT id retrieved correctly' );
+}
+
+1;

Modified: trunk/opsview-core/t/var/runtime.test.db
===================================================================
--- trunk/opsview-core/t/var/runtime.test.db	2012-10-22 14:47:18 UTC (rev 10568)
+++ trunk/opsview-core/t/var/runtime.test.db	2012-10-22 14:48:32 UTC (rev 10569)
@@ -989,7 +989,7 @@
 
 DROP TABLE IF EXISTS `nagios_hostchecks`;
 CREATE TABLE `nagios_hostchecks` (
-  `hostcheck_id` int(11) NOT NULL AUTO_INCREMENT,
+  `hostcheck_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
   `instance_id` smallint(6) NOT NULL DEFAULT '0',
   `host_object_id` int(11) NOT NULL DEFAULT '0',
   `check_type` smallint(6) NOT NULL DEFAULT '0',
@@ -13692,7 +13692,7 @@
 
 DROP TABLE IF EXISTS `snmptrapexceptions`;
 CREATE TABLE `snmptrapexceptions` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
   `time` varchar(16) DEFAULT NULL,
   `hostip` varchar(16) DEFAULT NULL,
   `trapname` varchar(128) DEFAULT NULL,

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to