From 31988ac63fb6472029f17ef61fd103a19a62404c Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Thu, 8 Mar 2007 17:24:52 +0000 Subject: [PATCH] change hardcoded rc_cur_id update into new flexible form --- .../archives/patch-rc_cur_id-not-null.sql | 1 + maintenance/updaters.inc | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 maintenance/postgres/archives/patch-rc_cur_id-not-null.sql 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 index 0000000000..2ca7edbfb5 --- /dev/null +++ b/maintenance/postgres/archives/patch-rc_cur_id-not-null.sql @@ -0,0 +1 @@ +ALTER TABLE recentchanges ALTER rc_cur_id DROP NOT NULL; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 5c860d35a6..327878ebbc 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1064,6 +1064,27 @@ END; return $exists; } +function +pg_column_is_nullable($table, $column) +{ +global $wgDatabase, $wgDBname, $wgDBmwschema; + + $q = <<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 .= <<