class PostgresUpdater extends DatabaseUpdater {
+ /**
+ * @var DatabasePostgres
+ */
+ protected $db;
+
/**
* @todo FIXME: Postgres should use sequential updates like Mysql, Sqlite
* and everybody else. It never got refactored like it should've.
array( 'renameSequence', 'rc_rc_id_seq', 'recentchanges_rc_id_seq' ),
array( 'renameSequence', 'log_log_id_seq', 'logging_log_id_seq' ),
array( 'renameSequence', 'pr_id_val', 'page_restrictions_pr_id_seq' ),
+ array( 'renameSequence', 'us_id_seq', 'uploadstash_us_id_seq' ),
# new tables
array( 'addTable', 'category', 'patch-category.sql' ),
array( 'addTable', 'msg_resource', 'patch-msg_resource.sql' ),
array( 'addTable', 'msg_resource_links','patch-msg_resource_links.sql' ),
array( 'addTable', 'module_deps', 'patch-module_deps.sql' ),
+ array( 'addTable', 'uploadstash', 'patch-uploadstash.sql' ),
+ array( 'addTable', 'user_former_groups','patch-user_former_groups.sql' ),
# Needed before new field
array( 'convertArchive2' ),
array( 'addPgField', 'logging', 'log_id', "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ),
array( 'addPgField', 'logging', 'log_params', 'TEXT' ),
array( 'addPgField', 'mwuser', 'user_editcount', 'INTEGER' ),
- array( 'addPgField', 'mwuser', 'user_hidden', 'SMALLINT NOT NULL DEFAULT 0' ),
array( 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ),
array( 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
array( 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ),
array( 'addPgField', 'logging', 'log_page', 'INTEGER' ),
array( 'addPgField', 'interwiki', 'iw_api', "TEXT NOT NULL DEFAULT ''"),
array( 'addPgField', 'interwiki', 'iw_wikiid', "TEXT NOT NULL DEFAULT ''"),
+ array( 'addPgField', 'revision', 'rev_sha1', "TEXT NOT NULL DEFAULT ''" ),
+ array( 'addPgField', 'archive', 'ar_sha1', "TEXT NOT NULL DEFAULT ''" ),
# type changes
array( 'changeField', 'archive', 'ar_deleted', 'smallint', '' ),
array( 'changeField', 'ipblocks', 'ipb_block_email', 'smallint', "CASE WHEN ipb_block_email=' ' THEN 0 ELSE ipb_block_email::smallint END DEFAULT 0" ),
array( 'changeField', 'ipblocks', 'ipb_address', 'text', 'ipb_address::text' ),
array( 'changeField', 'ipblocks', 'ipb_deleted', 'smallint', 'ipb_deleted::smallint DEFAULT 0' ),
- array( 'changeField', 'math', 'math_inputhash', 'bytea', "decode(math_inputhash,'escape')" ),
- array( 'changeField', 'math', 'math_outputhash', 'bytea', "decode(math_outputhash,'escape')" ),
array( 'changeField', 'mwuser', 'user_token', 'text', '' ),
array( 'changeField', 'mwuser', 'user_email_token', 'text', '' ),
array( 'changeField', 'objectcache', 'keyname', 'text', '' ),
array( 'changeFkeyDeferrable', 'revision', 'rev_page', 'page (page_id) ON DELETE CASCADE' ),
array( 'changeFkeyDeferrable', 'revision', 'rev_user', 'mwuser(user_id) ON DELETE RESTRICT' ),
array( 'changeFkeyDeferrable', 'templatelinks', 'tl_from', 'page(page_id) ON DELETE CASCADE' ),
- array( 'changeFkeyDeferrable', 'trackbacks', 'tb_page', 'page(page_id) ON DELETE CASCADE' ),
array( 'changeFkeyDeferrable', 'user_groups', 'ug_user', 'mwuser(user_id) ON DELETE CASCADE' ),
array( 'changeFkeyDeferrable', 'user_newtalk', 'user_id', 'mwuser(user_id) ON DELETE CASCADE' ),
array( 'changeFkeyDeferrable', 'user_properties', 'up_user', 'mwuser(user_id) ON DELETE CASCADE' ),
}
protected function renameSequence( $old, $new ) {
+ if ( $this->db->sequenceExists( $new ) ) {
+ $this->output( "WARNING sequence $new already exists\n" );
+ return;
+ }
if ( $this->db->sequenceExists( $old ) ) {
$this->output( "Renaming sequence $old to $new\n" );
$this->db->query( "ALTER SEQUENCE $old RENAME TO $new" );
}
$sql .= " USING $default";
}
- $sql .= ";\nCOMMIT;\n";
+ $this->db->begin( __METHOD__ );
$this->db->query( $sql );
+ $this->db->commit( __METHOD__ );
}
}
protected function tsearchFixes() {
# Tweak the page_title tsearch2 trigger to filter out slashes
# This is create or replace, so harmless to call if not needed
+ $this->output( "Refreshing ts2_page_title()...\n" );
$this->applyPatch( 'patch-ts2pagetitle.sql' );
# If the server is 8.3 or higher, rewrite the tsearch2 triggers
# in case they have the old 'default' versions
# Gather version numbers in case we need them
if ( $this->db->getServerVersion() >= 8.3 ) {
+ $this->output( "Rewriting tsearch2 triggers...\n" );
$this->applyPatch( 'patch-tsearch2funcs.sql' );
}
}