r20263 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20262‎ | r20263 | r20264 >
Date:20:05, 8 March 2007
Author:river
Status:old
Tags:
Comment:
make postgres pagelink_unique updater use new form
Modified paths:
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -1021,6 +1021,83 @@
10221022 }
10231023
10241024 function
 1025+pg_describe_table($table)
 1026+{
 1027+global $wgDatabase, $wgDBmwschema;
 1028+ $q = <<<END
 1029+SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
 1030+ WHERE pg_class.relnamespace = pg_namespace.oid
 1031+ AND attrelid=pg_class.oid AND attnum > 0
 1032+ AND relname=%s AND nspname=%s
 1033+END;
 1034+ $res = $wgDatabase->query(sprintf($q,
 1035+ $wgDatabase->addQuotes($table),
 1036+ $wgDatabase->addQuotes($wgDBmwschema)));
 1037+ if (!$res)
 1038+ return null;
 1039+
 1040+ $cols = array();
 1041+ while ($r = $wgDatabase->fetchRow($res)) {
 1042+ $cols[] = array(
 1043+ "name" => $r[0],
 1044+ "ord" => $r[1],
 1045+ );
 1046+ }
 1047+ return $cols;
 1048+}
 1049+
 1050+function
 1051+pg_describe_index($idx)
 1052+{
 1053+global $wgDatabase, $wgDBmwschema;
 1054+
 1055+ // first fetch the key (which is a list of columns ords) and
 1056+ // the table the index applies to (an oid)
 1057+ $q = <<<END
 1058+SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index
 1059+ WHERE nspname=%s
 1060+ AND pg_class.relnamespace = pg_namespace.oid
 1061+ AND relname=%s
 1062+ AND indexrelid=pg_class.oid
 1063+END;
 1064+ $res = $wgDatabase->query(sprintf($q,
 1065+ $wgDatabase->addQuotes($wgDBmwschema),
 1066+ $wgDatabase->addQuotes($idx)));
 1067+ if (!$res)
 1068+ return null;
 1069+ if (!($r = $wgDatabase->fetchRow($res))) {
 1070+ $wgDatabase->freeResult($res);
 1071+ return null;
 1072+ }
 1073+
 1074+ $indkey = $r[0];
 1075+ $relid = intval($r[1]);
 1076+ $indkeys = explode(" ", $indkey);
 1077+ $wgDatabase->freeResult($res);
 1078+
 1079+ $colnames = array();
 1080+ foreach ($indkeys as $rid) {
 1081+ $query = <<<END
 1082+SELECT attname FROM pg_class, pg_attribute
 1083+ WHERE attrelid=$relid
 1084+ AND attnum=%d
 1085+ AND attrelid=pg_class.oid
 1086+END;
 1087+ $r2 = $wgDatabase->query(sprintf($query, $rid));
 1088+ if (!$r2)
 1089+ return null;
 1090+ if (!($row2 = $wgDatabase->fetchRow($r2))) {
 1091+ $wgDatabase->freeResult($r2);
 1092+ return null;
 1093+ }
 1094+ $colnames[] = $row2[0];
 1095+ $wgDatabase->freeResult($r2);
 1096+ }
 1097+
 1098+ return $colnames;
 1099+}
 1100+
 1101+function
10251102 pg_column_has_type($table, $column, $wanttype)
10261103 {
10271104 global $wgDatabase, $wgDBname, $wgDBmwschema;
@@ -1290,22 +1367,20 @@
12911368 dbsource(archive('patch-rc_cur_id-not-null.sql'));
12921369 }
12931370
1294 - ## 1.8 Updater
1295 - if ($version < 1008) {
1296 - $upgrade .= <<<PGEND
 1371+ $pu = pg_describe_index("pagelink_unique");
 1372+ if (!is_null($pu) && ($pu[0] != "pl_from" || $pu[1] != "pl_namespace" || $pu[2] != "pl_title")) {
 1373+ echo "... dropping obsolete pagelink_unique index\n";
 1374+ $wgDatabase->query("DROP INDEX pagelink_unique");
 1375+ $pu = null;
 1376+ } else
 1377+ echo "... obsolete pagelink_unique index not present\n";
12971378
1298 -DROP INDEX pagelink_unique;
1299 -CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title);
 1379+ if (is_null($pu)) {
 1380+ echo "... adding new pagelink_unique index\n";
 1381+ $wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)");
 1382+ } else
 1383+ echo "... already have current pagelink_unique index\n";
13001384
1301 -INSERT INTO mediawiki_version (type,mw_version,notes)
1302 -VALUES ('Upgrade','MWVERSION','Upgrade from older pre 1.8 version THISVERSION aka SVERSION');
1303 -
1304 -PGEND;
1305 -
1306 - } ## end version 1.8
1307 -
13081385 ## 1.9 Updater
13091386 if ($version < 1009) {
13101387 $upgrade = <<<PGEND