summaryrefslogtreecommitdiff
path: root/includes/installer/PostgresUpdater.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
committerPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
commitd9022f63880ce039446fba8364f68e656b7bf4cb (patch)
tree16b40fbf17bf7c9ee6f4ead25b16dd192378050a /includes/installer/PostgresUpdater.php
parent27cf83d177256813e2e802241085fce5dd0f3fb9 (diff)
Update to MediaWiki 1.19.0
Diffstat (limited to 'includes/installer/PostgresUpdater.php')
-rw-r--r--includes/installer/PostgresUpdater.php65
1 files changed, 44 insertions, 21 deletions
diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php
index ade46ac8..023cb300 100644
--- a/includes/installer/PostgresUpdater.php
+++ b/includes/installer/PostgresUpdater.php
@@ -16,11 +16,21 @@
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.
*/
protected function getCoreUpdateList() {
return array(
+ # rename tables 1.7.3
+ # r15791 Change reserved word table names "user" and "text"
+ array( 'renameTable', 'user', 'mwuser'),
+ array( 'renameTable', 'text', 'pagecontent'),
+
# new sequences
array( 'addSequence', 'logging_log_id_seq' ),
array( 'addSequence', 'page_restrictions_pr_id_seq' ),
@@ -55,7 +65,8 @@ class PostgresUpdater extends DatabaseUpdater {
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', 'uploadstash', 'patch-uploadstash.sql' ),
+ array( 'addTable', 'user_former_groups','patch-user_former_groups.sql' ),
# Needed before new field
array( 'convertArchive2' ),
@@ -108,6 +119,10 @@ class PostgresUpdater extends DatabaseUpdater {
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 ''" ),
+ array( 'addPgField', 'uploadstash', 'us_chunk_inx', "INTEGER NULL" ),
+ array( 'addPgField', 'job', 'job_timestamp', "TIMESTAMPTZ" ),
# type changes
array( 'changeField', 'archive', 'ar_deleted', 'smallint', '' ),
@@ -175,6 +190,7 @@ class PostgresUpdater extends DatabaseUpdater {
array( 'addPgIndex', 'logging', 'logging_user_type_time', '(log_user, log_type, log_timestamp)' ),
array( 'addPgIndex', 'logging', 'logging_page_id_time', '(log_page,log_timestamp)' ),
array( 'addPgIndex', 'iwlinks', 'iwl_prefix_title_from', '(iwl_prefix, iwl_title, iwl_from)' ),
+ array( 'addPgIndex', 'job', 'job_timestamp_idx', '(job_timestamp)' ),
array( 'checkOiNameConstraint' ),
array( 'checkPageDeletedTrigger' ),
@@ -208,7 +224,6 @@ class PostgresUpdater extends DatabaseUpdater {
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' ),
@@ -387,6 +402,10 @@ END;
}
protected function renameSequence( $old, $new ) {
+ if ( $this->db->sequenceExists( $new ) ) {
+ $this->output( "...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" );
@@ -396,7 +415,8 @@ END;
protected function renameTable( $old, $new ) {
if ( $this->db->tableExists( $old ) ) {
$this->output( "Renaming table $old to $new\n" );
- $old = $this->db->addQuotes( $old );
+ $old = $this->db->realTableName( $old, "quoted" );
+ $new = $this->db->realTableName( $new, "quoted" );
$this->db->query( "ALTER TABLE $old RENAME TO $new" );
}
}
@@ -404,7 +424,7 @@ END;
protected function addPgField( $table, $field, $type ) {
$fi = $this->db->fieldInfo( $table, $field );
if ( !is_null( $fi ) ) {
- $this->output( "... column '$table.$field' already exists\n" );
+ $this->output( "...column '$table.$field' already exists\n" );
return;
} else {
$this->output( "Adding column '$table.$field'\n" );
@@ -415,12 +435,12 @@ END;
protected function changeField( $table, $field, $newtype, $default ) {
$fi = $this->db->fieldInfo( $table, $field );
if ( is_null( $fi ) ) {
- $this->output( "... error: expected column $table.$field to exist\n" );
+ $this->output( "...ERROR: expected column $table.$field to exist\n" );
exit( 1 );
}
if ( $fi->type() === $newtype )
- $this->output( "... column '$table.$field' is already of type '$newtype'\n" );
+ $this->output( "...column '$table.$field' is already of type '$newtype'\n" );
else {
$this->output( "Changing column type of '$table.$field' from '{$fi->type()}' to '$newtype'\n" );
$sql = "ALTER TABLE $table ALTER $field TYPE $newtype";
@@ -433,15 +453,16 @@ END;
}
$sql .= " USING $default";
}
- $sql .= ";\nCOMMIT;\n";
+ $this->db->begin( __METHOD__ );
$this->db->query( $sql );
+ $this->db->commit( __METHOD__ );
}
}
protected function changeNullableField( $table, $field, $null ) {
$fi = $this->db->fieldInfo( $table, $field );
if ( is_null( $fi ) ) {
- $this->output( "... error: expected column $table.$field to exist\n" );
+ $this->output( "...ERROR: expected column $table.$field to exist\n" );
exit( 1 );
}
if ( $fi->isNullable() ) {
@@ -450,7 +471,7 @@ END;
$this->output( "Changing '$table.$field' to not allow NULLs\n" );
$this->db->query( "ALTER TABLE $table ALTER $field SET NOT NULL" );
} else {
- $this->output( "... column '$table.$field' is already set as NULL\n" );
+ $this->output( "...column '$table.$field' is already set as NULL\n" );
}
} else {
# # It's NOT NULL - does it need to be NULL?
@@ -459,14 +480,14 @@ END;
$this->db->query( "ALTER TABLE $table ALTER $field DROP NOT NULL" );
}
else {
- $this->output( "... column '$table.$field' is already set as NOT NULL\n" );
+ $this->output( "...column '$table.$field' is already set as NOT NULL\n" );
}
}
}
public function addPgIndex( $table, $index, $type ) {
if ( $this->db->indexExists( $table, $index ) ) {
- $this->output( "... index '$index' on table '$table' already exists\n" );
+ $this->output( "...index '$index' on table '$table' already exists\n" );
} else {
$this->output( "Creating index '$index' on table '$table' $type\n" );
$this->db->query( "CREATE INDEX $index ON $table $type" );
@@ -475,7 +496,7 @@ END;
public function addPgExtIndex( $table, $index, $type ) {
if ( $this->db->indexExists( $table, $index ) ) {
- $this->output( "... index '$index' on table '$table' already exists\n" );
+ $this->output( "...index '$index' on table '$table' already exists\n" );
} else {
$this->output( "Creating index '$index' on table '$table'\n" );
if ( preg_match( '/^\(/', $type ) ) {
@@ -516,7 +537,7 @@ END;
}
$this->applyPatch( 'patch-remove-archive2.sql' );
} else {
- $this->output( "... obsolete table 'archive2' does not exist\n" );
+ $this->output( "...obsolete table 'archive2' does not exist\n" );
}
}
@@ -527,13 +548,13 @@ END;
$this->db->query( "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
$this->db->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
} else {
- $this->output( "... column 'oldimage.oi_deleted' is already of type 'smallint'\n" );
+ $this->output( "...column 'oldimage.oi_deleted' is already of type 'smallint'\n" );
}
}
protected function checkOiNameConstraint() {
if ( $this->db->hasConstraint( "oldimage_oi_name_fkey_cascaded" ) ) {
- $this->output( "... table 'oldimage' has correct cascading delete/update foreign key to image\n" );
+ $this->output( "...table 'oldimage' has correct cascading delete/update foreign key to image\n" );
} else {
if ( $this->db->hasConstraint( "oldimage_oi_name_fkey" ) ) {
$this->db->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
@@ -552,7 +573,7 @@ END;
$this->output( "Adding function and trigger 'page_deleted' to table 'page'\n" );
$this->applyPatch( 'patch-page_deleted.sql' );
} else {
- $this->output( "... table 'page' has 'page_deleted' trigger\n" );
+ $this->output( "...table 'page' has 'page_deleted' trigger\n" );
}
}
@@ -562,7 +583,7 @@ END;
$this->output( "Removing NOT NULL constraint from 'recentchanges.rc_cur_id'\n" );
$this->applyPatch( 'patch-rc_cur_id-not-null.sql' );
} else {
- $this->output( "... column 'recentchanges.rc_cur_id' has a NOT NULL constraint\n" );
+ $this->output( "...column 'recentchanges.rc_cur_id' has a NOT NULL constraint\n" );
}
}
@@ -573,20 +594,20 @@ END;
$this->db->query( 'DROP INDEX pagelink_unique' );
$pu = null;
} else {
- $this->output( "... obsolete version of index 'pagelink_unique index' does not exist\n" );
+ $this->output( "...obsolete version of index 'pagelink_unique index' does not exist\n" );
}
if ( is_null( $pu ) ) {
$this->output( "Creating index 'pagelink_unique index'\n" );
$this->db->query( 'CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)' );
} else {
- $this->output( "... index 'pagelink_unique_index' already exists\n" );
+ $this->output( "...index 'pagelink_unique_index' already exists\n" );
}
}
protected function checkRevUserFkey() {
if ( $this->fkeyDeltype( 'revision_rev_user_fkey' ) == 'r' ) {
- $this->output( "... constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" );
+ $this->output( "...constraint 'revision_rev_user_fkey' is ON DELETE RESTRICT\n" );
} else {
$this->output( "Changing constraint 'revision_rev_user_fkey' to ON DELETE RESTRICT\n" );
$this->applyPatch( 'patch-revision_rev_user_fkey.sql' );
@@ -599,7 +620,7 @@ END;
$this->db->query( 'DROP INDEX ipb_address' );
}
if ( $this->db->indexExists( 'ipblocks', 'ipb_address_unique' ) ) {
- $this->output( "... have ipb_address_unique\n" );
+ $this->output( "...have ipb_address_unique\n" );
} else {
$this->output( "Adding ipb_address_unique index\n" );
$this->applyPatch( 'patch-ipb_address_unique.sql' );
@@ -616,12 +637,14 @@ END;
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' );
}
}