From 275c95cdf7fb1968c694675818c7fc3d92ee78ec Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Thu, 8 Mar 2007 20:05:47 +0000 Subject: [PATCH] make postgres pagelink_unique updater use new form --- maintenance/updaters.inc | 103 +++++++++++++++++++++++++++++++++------ 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index ef2c42ab4d..a404c7ae1e 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1020,6 +1020,83 @@ function do_restrictions_update() { } +function +pg_describe_table($table) +{ +global $wgDatabase, $wgDBmwschema; + $q = << 0 + AND relname=%s AND nspname=%s +END; + $res = $wgDatabase->query(sprintf($q, + $wgDatabase->addQuotes($table), + $wgDatabase->addQuotes($wgDBmwschema))); + if (!$res) + return null; + + $cols = array(); + while ($r = $wgDatabase->fetchRow($res)) { + $cols[] = array( + "name" => $r[0], + "ord" => $r[1], + ); + } + return $cols; +} + +function +pg_describe_index($idx) +{ +global $wgDatabase, $wgDBmwschema; + + // first fetch the key (which is a list of columns ords) and + // the table the index applies to (an oid) + $q = <<query(sprintf($q, + $wgDatabase->addQuotes($wgDBmwschema), + $wgDatabase->addQuotes($idx))); + if (!$res) + return null; + if (!($r = $wgDatabase->fetchRow($res))) { + $wgDatabase->freeResult($res); + return null; + } + + $indkey = $r[0]; + $relid = intval($r[1]); + $indkeys = explode(" ", $indkey); + $wgDatabase->freeResult($res); + + $colnames = array(); + foreach ($indkeys as $rid) { + $query = <<query(sprintf($query, $rid)); + if (!$r2) + return null; + if (!($row2 = $wgDatabase->fetchRow($r2))) { + $wgDatabase->freeResult($r2); + return null; + } + $colnames[] = $row2[0]; + $wgDatabase->freeResult($r2); + } + + return $colnames; +} + function pg_column_has_type($table, $column, $wanttype) { @@ -1290,21 +1367,19 @@ function do_postgres_updates() { dbsource(archive('patch-rc_cur_id-not-null.sql')); } - ## 1.8 Updater - if ($version < 1008) { - $upgrade .= <<query("DROP INDEX pagelink_unique"); + $pu = null; + } else + echo "... obsolete pagelink_unique index not present\n"; - } ## end version 1.8 + if (is_null($pu)) { + echo "... adding new pagelink_unique index\n"; + $wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)"); + } else + echo "... already have current pagelink_unique index\n"; ## 1.9 Updater if ($version < 1009) { -- 2.20.1