r20311 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20310‎ | r20311 | r20312 >
Date:18:41, 10 March 2007
Author:river
Status:old
Tags:
Comment:
postgres updaters for r20302
Modified paths:
  • /trunk/phase3/maintenance/postgres/archives/patch-archive2-ar_deleted.sql (added) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/postgres/archives/patch-archive2-ar_deleted.sql
@@ -0,0 +1,18 @@
 2+ALTER TABLE archive2 ADD ar_deleted INTEGER NOT NULL DEFAULT '0';
 3+DROP VIEW archive;
 4+
 5+CREATE VIEW archive AS
 6+SELECT
 7+ ar_namespace, ar_title, ar_text, ar_comment, ar_user, ar_user_text,
 8+ ar_minor_edit, ar_flags, ar_rev_id, ar_text_id, ar_deleted,
 9+ TO_CHAR(ar_timestamp, 'YYYYMMDDHH24MISS') AS ar_timestamp
 10+FROM archive2;
 11+
 12+CREATE RULE archive_insert AS ON INSERT TO archive
 13+DO INSTEAD INSERT INTO archive2 VALUES (
 14+ NEW.ar_namespace, NEW.ar_title, NEW.ar_text, NEW.ar_comment, NEW.ar_user, NEW.ar_user_text,
 15+ TO_TIMESTAMP(NEW.ar_timestamp, 'YYYYMMDDHH24MISS'),
 16+ NEW.ar_minor_edit, NEW.ar_flags, NEW.ar_rev_id, NEW.ar_text_id, NEW.ar_deleted
 17+);
 18+
 19+
Index: trunk/phase3/maintenance/updaters.inc
@@ -1168,19 +1168,23 @@
11691169 return $nullable;
11701170 }
11711171
 1172+define('PG_RELTYPE_TABLE', 'r');
 1173+define('PG_RELTYPE_SEQUENCE', 'S');
 1174+
11721175 function
1173 -pg_table_exists($table)
 1176+pg_relation_exists($rel, $type)
11741177 {
11751178 global $wgDatabase, $wgDBname, $wgDBmwschema;
11761179
11771180 $q = <<<END
11781181 SELECT 1 FROM pg_class, pg_namespace
1179 - WHERE relnamespace=pg_namespace.oid AND relkind='r'
 1182+ WHERE relnamespace=pg_namespace.oid AND relkind=%s
11801183 AND nspname=%s AND relname=%s
11811184 END;
11821185 $res = $wgDatabase->query(sprintf($q,
 1186+ $wgDatabase->addQuotes($type),
11831187 $wgDatabase->addQuotes($wgDBmwschema),
1184 - $wgDatabase->addQuotes($table)));
 1188+ $wgDatabase->addQuotes($rel)));
11851189 $row = $wgDatabase->fetchRow($res);
11861190 $exists = !!$row;
11871191 $wgDatabase->freeResult($res);
@@ -1188,6 +1192,18 @@
11891193 }
11901194
11911195 function
 1196+pg_table_exists($table)
 1197+{
 1198+ return pg_relation_exists($table, PG_RELTYPE_TABLE);
 1199+}
 1200+
 1201+function
 1202+pg_sequence_exists($seq)
 1203+{
 1204+ return pg_relation_exists($seq, PG_RELTYPE_SEQUENCE);
 1205+}
 1206+
 1207+function
11921208 pg_trigger_exists($table, $trigger)
11931209 {
11941210 global $wgDatabase, $wgDBname, $wgDBmwschema;
@@ -1293,9 +1309,19 @@
12941310 array("ipblocks", "ipb_anon_only", "CHAR NOT NULL DEFAULT '0'"),
12951311 array("ipblocks", "ipb_create_account", "CHAR NOT NULL DEFAULT '1'"),
12961312 array("ipblocks", "ipb_enable_autoblock", "CHAR NOT NULL DEFAULT '1'"),
 1313+ array("ipblocks", "ipb_deleted", "INTEGER NOT NULL DEFAULT '0'"),
12971314 array("recentchanges", "rc_old_len", "INT"),
12981315 array("recentchanges", "rc_new_len", "INT"),
1299 - array("revision", "rev_len", "INT")
 1316+ array("revision", "rev_len", "INT"),
 1317+ array("filearchive", "fa_deleted", "INTEGER NOT NULL DEFAULT '0'"),
 1318+ array("recentchanges", "rc_deleted", "INTEGER NOT NULL DEFAULT '0'"),
 1319+ array("recentchanges", "rc_logid", "INTEGER NOT NULL DEFAULT '0'"),
 1320+ array("recentchanges", "rc_log_type", "TEXT"),
 1321+ array("recentchanges", "rc_log_action", "TEXT"),
 1322+ array("recentchanges", "rc_params", "TEXT"),
 1323+ array("logging", "log_id", "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('log_log_id_seq')"),
 1324+ array("logging", "log_params", "TEXT"),
 1325+ array("logging", "log_deleted", "INTEGER NOT NULL DEFAULT '0'")
13001326 );
13011327
13021328 $newtables = array(
@@ -1309,6 +1335,10 @@
13101336 array("archive2", "patch-archive2.sql")
13111337 );
13121338
 1339+ $newsequences = array(
 1340+ "log_log_id_seq"
 1341+ );
 1342+
13131343 $newindexes = array(
13141344 array("revision", "rev_text_id_idx", "patch-rev_text_id_idx.sql")
13151345 );
@@ -1317,6 +1347,16 @@
13181348 array("archive", "archive_delete", "patch-archive_delete.sql")
13191349 );
13201350
 1351+ foreach ($newsequences as $ns) {
 1352+ if (pg_sequence_exists($ns)) {
 1353+ echo "... sequence $ns already exists\n";
 1354+ continue;
 1355+ }
 1356+
 1357+ echo "... create sequence $ns\n";
 1358+ $wgDatabase->query("CREATE SEQUENCE $ns");
 1359+ }
 1360+
13211361 foreach ($newtables as $nt) {
13221362 if (pg_table_exists($nt[0])) {
13231363 echo "... table $nt[0] already exists\n";
@@ -1416,6 +1456,12 @@
14171457 } else
14181458 echo "... already have correct archive_insert rule\n";
14191459
 1460+ if (!pg_column_exists("archive2", "ar_deleted")) {
 1461+ echo "... add archive2.ar_deleted and recreate archive view\n";
 1462+ dbsource(archive("patch-archive2-ar_deleted.sql"));
 1463+ } else
 1464+ echo "... already have archive2.ar_deleted\n";
 1465+
14201466 return;
14211467 }
14221468

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r20302*Add bitfields to various tables for revisiondeleteaaron21:51, 9 March 2007