--- /dev/null
+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
+);
+
+
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 = <<<END
SELECT 1 FROM pg_class, pg_namespace
- WHERE relnamespace=pg_namespace.oid AND relkind='r'
+ WHERE relnamespace=pg_namespace.oid AND relkind=%s
AND nspname=%s AND relname=%s
END;
$res = $wgDatabase->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)
{
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(
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")
);
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";
} 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;
}