change hardcoded rc_cur_id update into new flexible form
authorRiver Tarnell <river@users.mediawiki.org>
Thu, 8 Mar 2007 17:24:52 +0000 (17:24 +0000)
committerRiver Tarnell <river@users.mediawiki.org>
Thu, 8 Mar 2007 17:24:52 +0000 (17:24 +0000)
maintenance/postgres/archives/patch-rc_cur_id-not-null.sql [new file with mode: 0644]
maintenance/updaters.inc

diff --git a/maintenance/postgres/archives/patch-rc_cur_id-not-null.sql b/maintenance/postgres/archives/patch-rc_cur_id-not-null.sql
new file mode 100644 (file)
index 0000000..2ca7edb
--- /dev/null
@@ -0,0 +1 @@
+ALTER TABLE recentchanges ALTER rc_cur_id DROP NOT NULL;
index 5c860d3..327878e 100644 (file)
@@ -1064,6 +1064,27 @@ END;
        return $exists;
 }
 
+function
+pg_column_is_nullable($table, $column)
+{
+global $wgDatabase, $wgDBname, $wgDBmwschema;
+
+       $q = <<<END
+SELECT attnotnull FROM pg_class, pg_namespace, pg_attribute
+       WHERE relnamespace=pg_namespace.oid AND relkind='r'
+             AND attrelid=pg_class.oid
+             AND nspname=%s AND relname=%s AND attname=%s;
+END;
+       $res = $wgDatabase->query(sprintf($q,
+                       $wgDatabase->addQuotes($wgDBmwschema),
+                       $wgDatabase->addQuotes($table),
+                       $wgDatabase->addQuotes($column)));
+       $row = $wgDatabase->fetchRow($res);
+       $nullable = ($row[0] === 'f');
+       $wgDatabase->freeResult($res);
+       return $nullable;
+}
+
 function
 pg_table_exists($table)
 {
@@ -1258,13 +1279,15 @@ function do_postgres_updates() {
                dbsource(archive('patch-page_deleted.sql'));
        }
 
+       if (!pg_column_is_nullable("recentchanges", "rc_cur_id")) {
+               echo "... remove NOT NULL constraint on recentchanges.rc_cur_id\n";
+               dbsource(archive('patch-rc_cur_id-not-null.sql'));
+       }
+
        ## 1.8 Updater
        if ($version < 1008) {
                $upgrade .= <<<PGEND
 
--- Constraint tweaking:
-ALTER TABLE recentchanges ALTER rc_cur_id DROP NOT NULL;
-
 -- Index order rearrangements:
 DROP INDEX pagelink_unique;
 CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title);