From 65975323459cbf0808b8659dfa4abc40f9ac6fbe Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Sat, 10 Mar 2007 19:06:40 +0000 Subject: [PATCH] drop obsolete archive2 table; it doesn't work and Special:Delete/Undelete work fine without it --- .../archives/patch-archive-ar_deleted.sql | 1 + .../archives/patch-archive2-ar_deleted.sql | 17 ---------- .../archives/patch-remove-archive2.sql | 2 ++ maintenance/postgres/tables.sql | 26 +--------------- maintenance/updaters.inc | 31 ++++++++++++------- 5 files changed, 24 insertions(+), 53 deletions(-) create mode 100644 maintenance/postgres/archives/patch-archive-ar_deleted.sql delete mode 100644 maintenance/postgres/archives/patch-archive2-ar_deleted.sql create mode 100644 maintenance/postgres/archives/patch-remove-archive2.sql diff --git a/maintenance/postgres/archives/patch-archive-ar_deleted.sql b/maintenance/postgres/archives/patch-archive-ar_deleted.sql new file mode 100644 index 0000000000..08bc1e3712 --- /dev/null +++ b/maintenance/postgres/archives/patch-archive-ar_deleted.sql @@ -0,0 +1 @@ +ALTER TABLE archive ADD ar_deleted INTEGER NOT NULL DEFAULT '0'; diff --git a/maintenance/postgres/archives/patch-archive2-ar_deleted.sql b/maintenance/postgres/archives/patch-archive2-ar_deleted.sql deleted file mode 100644 index 3c59fd184c..0000000000 --- a/maintenance/postgres/archives/patch-archive2-ar_deleted.sql +++ /dev/null @@ -1,17 +0,0 @@ -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, - COALESCE(NEW.ar_deleted, 0) -- ar_deleted is not always specified -); diff --git a/maintenance/postgres/archives/patch-remove-archive2.sql b/maintenance/postgres/archives/patch-remove-archive2.sql new file mode 100644 index 0000000000..122ac174e9 --- /dev/null +++ b/maintenance/postgres/archives/patch-remove-archive2.sql @@ -0,0 +1,2 @@ +DROP VIEW archive; +ALTER TABLE archive2 RENAME TO archive; diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql index 10ca78f483..ac0cc36da6 100644 --- a/maintenance/postgres/tables.sql +++ b/maintenance/postgres/tables.sql @@ -123,8 +123,7 @@ CREATE TABLE page_restrictions ( ); ALTER TABLE page_restrictions ADD CONSTRAINT page_restrictions_pk PRIMARY KEY (pr_page,pr_type); - -CREATE TABLE archive2 ( +CREATE TABLE archive ( ar_namespace SMALLINT NOT NULL, ar_title TEXT NOT NULL, ar_text TEXT, @@ -140,29 +139,6 @@ CREATE TABLE archive2 ( ); CREATE INDEX archive_name_title_timestamp ON archive2 (ar_namespace,ar_title,ar_timestamp); --- This is the easiest way to work around the char(15) timestamp hack without modifying PHP code -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, - COALESCE(NEW.ar_deleted, 0) -- NEW.ar_deleted might be unspecified (NULL) -); - -CREATE RULE archive_delete AS ON DELETE TO archive -DO INSTEAD DELETE FROM archive2 WHERE - archive2.ar_title = OLD.ar_title AND - archive2.ar_namespace = OLD.ar_namespace AND - archive2.ar_rev_id = OLD.ar_rev_id; - - CREATE TABLE redirect ( rd_from INTEGER NOT NULL REFERENCES page(page_id) ON DELETE CASCADE, rd_namespace SMALLINT NOT NULL, diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 932cb0d347..2fe36538d8 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1332,7 +1332,7 @@ function do_postgres_updates() { array("page_restrictions", "patch-page_restrictions.sql"), array("profiling", "patch-profiling.sql"), array("mediawiki_version", "patch-mediawiki_version.sql"), - array("archive2", "patch-archive2.sql") + // array("archive2", "patch-archive2.sql") ); $newsequences = array( @@ -1344,7 +1344,8 @@ function do_postgres_updates() { ); $newrules = array( - array("archive", "archive_delete", "patch-archive_delete.sql") + //array("archive", "archive_delete", + //"patch-archive_delete.sql") ); foreach ($newsequences as $ns) { @@ -1449,18 +1450,26 @@ function do_postgres_updates() { dbsource(archive('patch-revision_rev_user_fkey.sql')); } - $ai_def = pg_rule_def("archive", "archive_insert"); - if (strstr($ai_def, "to_date") !== false) { - echo "... fix archive_insert rule\n"; - dbsource(archive('patch-archive_insert.sql')); + if (pg_table_exists("archive2")) { + echo "... convert archive2 back to normal archive table\n"; + if (pg_rule_exists("archive", "archive_insert")) { + echo "... drop rule archive_insert\n"; + $wgDatabase->query("DROP RULE archive_insert ON archive"); + } + if (pg_rule_exists("archive", "archive_delete")) { + echo "... drop rule archive_delete\n"; + $wgDatabase->query("DROP RULE archive_delete ON archive"); + } + + dbsource(archive("patch-remove-archive2.sql")); } else - echo "... already have correct archive_insert rule\n"; + echo "... obsolete archive2 not present\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")); + if (!pg_column_exists("archive", "ar_deleted")) { + echo "... add archive.ar_deleted\n"; + dbsource(archive("patch-archive-ar_deleted.sql")); } else - echo "... already have archive2.ar_deleted\n"; + echo "... archive.ar_deleted already exists\n"; return; } -- 2.20.1