r2707 - make PortCompat pairs unique
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 8 May 2009 18:01:40 +0000 (18:01 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 8 May 2009 18:01:40 +0000 (18:01 +0000)
install/init-dictbase.sql
install/init-structure.sql
upgrade.php

index 3914e294c2e92a6555253117d09aaadde3a47c38..3c2602bfa2ede0d2564f81dd4e46cbeb50b1db46 100644 (file)
@@ -145,37 +145,8 @@ INSERT INTO `PortCompat` (`type1`, `type2`) VALUES
 (28,27),
 (30,30),
 (16,16),
-(17,17),
-(18,18),
-(19,19),
-(20,20),
-(21,21),
-(22,22),
-(23,23),
-(24,24),
-(25,25),
-(26,26),
-(27,27),
-(28,28),
-(18,19),
-(19,18),
-(18,24),
-(24,18),
-(19,24),
-(24,19),
-(29,29),
 (29,681),
 (29,682),
-(20,21),
-(21,20),
-(22,23),
-(23,22),
-(25,26),
-(26,25),
-(27,28),
-(28,27),
-(30,30),
-(16,16),
 (32,32),
 (33,446),
 (34,34),
index f599580e0688bc0ac76899642c60a9df5ea37c1c..c0d399338bbf88c4e2b60bdc839eaed79fa6e204 100644 (file)
@@ -199,7 +199,7 @@ CREATE TABLE `Port` (
 CREATE TABLE `PortCompat` (
   `type1` int(10) unsigned NOT NULL,
   `type2` int(10) unsigned NOT NULL,
-  KEY `type1` (`type1`),
+  UNIQUE KEY `type1_2` (`type1`,`type2`),
   KEY `type2` (`type2`)
 ) ENGINE=MyISAM;
 
index 9b8dbb47b950ce4f91fc52ebb5774d0f434330dd..f2d8c1440e99388aedd0b205355b0d9958b7eb8e 100644 (file)
@@ -236,6 +236,13 @@ CREATE TABLE `LDAPCache` (
                        $query[] = 'ALTER TABLE RackHistory DROP COLUMN deleted';
                        $query[] = 'ALTER TABLE RackObject DROP COLUMN deleted';
                        $query[] = 'ALTER TABLE RackObjectHistory DROP COLUMN deleted';
+                       // Can't be added straight due to many duplicates, even in "dictbase" data.
+                       $result = $dbxlink->query ('SELECT type1, type2, count(*) - 1 as excess FROM PortCompat GROUP BY type1, type2 HAVING excess > 0');
+                       while ($row = $result->fetch (PDO::FETCH_ASSOC))
+                               $query[] = "DELETE FROM PortCompat WHERE type1 = ${row['type1']} AND type2 = ${row['type2']} limit ${row['excess']}";
+                       unset ($result);
+                       $query[] = 'ALTER TABLE PortCompat DROP KEY type1';
+                       $query[] = 'ALTER TABLE PortCompat ADD UNIQUE (type1, type2)';
                        $query[] = "UPDATE Config SET varvalue = '0.17.0' WHERE varname = 'DB_VERSION'";
 
                        break;