From 838fdbe9442d27954d25d6c2f37f76fb48b033bd Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Sat, 10 Mar 2007 18:41:14 +0000 Subject: [PATCH] postgres updaters for r20302 --- .../archives/patch-archive2-ar_deleted.sql | 18 +++++++ maintenance/updaters.inc | 54 +++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 maintenance/postgres/archives/patch-archive2-ar_deleted.sql diff --git a/maintenance/postgres/archives/patch-archive2-ar_deleted.sql b/maintenance/postgres/archives/patch-archive2-ar_deleted.sql new file mode 100644 index 0000000000..e05459ca45 --- /dev/null +++ b/maintenance/postgres/archives/patch-archive2-ar_deleted.sql @@ -0,0 +1,18 @@ +ALTER TABLE archive2 ADD ar_deleted INTEGER NOT NULL DEFAULT '0'; +DROP VIEW archive; + +CREATE VIEW archive AS +SELECT + ar_namespace, ar_title, ar_text, ar_comment, ar_user, ar_user_text, + ar_minor_edit, ar_flags, ar_rev_id, ar_text_id, ar_deleted, + TO_CHAR(ar_timestamp, 'YYYYMMDDHH24MISS') AS ar_timestamp +FROM archive2; + +CREATE RULE archive_insert AS ON INSERT TO archive +DO INSTEAD INSERT INTO archive2 VALUES ( + NEW.ar_namespace, NEW.ar_title, NEW.ar_text, NEW.ar_comment, NEW.ar_user, NEW.ar_user_text, + TO_TIMESTAMP(NEW.ar_timestamp, 'YYYYMMDDHH24MISS'), + NEW.ar_minor_edit, NEW.ar_flags, NEW.ar_rev_id, NEW.ar_text_id, NEW.ar_deleted +); + + diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index c65e4f328f..932cb0d347 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1168,25 +1168,41 @@ END; return $nullable; } +define('PG_RELTYPE_TABLE', 'r'); +define('PG_RELTYPE_SEQUENCE', 'S'); + function -pg_table_exists($table) +pg_relation_exists($rel, $type) { global $wgDatabase, $wgDBname, $wgDBmwschema; $q = <<query(sprintf($q, + $wgDatabase->addQuotes($type), $wgDatabase->addQuotes($wgDBmwschema), - $wgDatabase->addQuotes($table))); + $wgDatabase->addQuotes($rel))); $row = $wgDatabase->fetchRow($res); $exists = !!$row; $wgDatabase->freeResult($res); return $exists; } +function +pg_table_exists($table) +{ + return pg_relation_exists($table, PG_RELTYPE_TABLE); +} + +function +pg_sequence_exists($seq) +{ + return pg_relation_exists($seq, PG_RELTYPE_SEQUENCE); +} + function pg_trigger_exists($table, $trigger) { @@ -1293,9 +1309,19 @@ function do_postgres_updates() { array("ipblocks", "ipb_anon_only", "CHAR NOT NULL DEFAULT '0'"), array("ipblocks", "ipb_create_account", "CHAR NOT NULL DEFAULT '1'"), array("ipblocks", "ipb_enable_autoblock", "CHAR NOT NULL DEFAULT '1'"), + array("ipblocks", "ipb_deleted", "INTEGER NOT NULL DEFAULT '0'"), array("recentchanges", "rc_old_len", "INT"), array("recentchanges", "rc_new_len", "INT"), - array("revision", "rev_len", "INT") + array("revision", "rev_len", "INT"), + array("filearchive", "fa_deleted", "INTEGER NOT NULL DEFAULT '0'"), + array("recentchanges", "rc_deleted", "INTEGER NOT NULL DEFAULT '0'"), + array("recentchanges", "rc_logid", "INTEGER NOT NULL DEFAULT '0'"), + array("recentchanges", "rc_log_type", "TEXT"), + array("recentchanges", "rc_log_action", "TEXT"), + array("recentchanges", "rc_params", "TEXT"), + array("logging", "log_id", "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('log_log_id_seq')"), + array("logging", "log_params", "TEXT"), + array("logging", "log_deleted", "INTEGER NOT NULL DEFAULT '0'") ); $newtables = array( @@ -1309,6 +1335,10 @@ function do_postgres_updates() { array("archive2", "patch-archive2.sql") ); + $newsequences = array( + "log_log_id_seq" + ); + $newindexes = array( array("revision", "rev_text_id_idx", "patch-rev_text_id_idx.sql") ); @@ -1317,6 +1347,16 @@ function do_postgres_updates() { array("archive", "archive_delete", "patch-archive_delete.sql") ); + foreach ($newsequences as $ns) { + if (pg_sequence_exists($ns)) { + echo "... sequence $ns already exists\n"; + continue; + } + + echo "... create sequence $ns\n"; + $wgDatabase->query("CREATE SEQUENCE $ns"); + } + foreach ($newtables as $nt) { if (pg_table_exists($nt[0])) { echo "... table $nt[0] already exists\n"; @@ -1416,6 +1456,12 @@ function do_postgres_updates() { } else echo "... already have correct archive_insert rule\n"; + if (!pg_column_exists("archive2", "ar_deleted")) { + echo "... add archive2.ar_deleted and recreate archive view\n"; + dbsource(archive("patch-archive2-ar_deleted.sql")); + } else + echo "... already have archive2.ar_deleted\n"; + return; } -- 2.20.1