Rename "user" and "text" when upgrading on PostgreSQL

Follow-up to r15791.

You can lie to me, but not to your installer.

Make DatabasePostgres::tableExists to check for real table names, not
faked ones.

DatabasePostgres is currently lying to the rest of the MediaWiki that
"mwuser" table is actually called "user" and that "pagecontents" is
called "text". While MediaWiki does not care, the installer (and updater
do).

This allows us to overcome first hurdle in getting MediaWiki 1.7.3 to
update to trunk on PostgreSQL and uncover further bugs.

For this commit to actually do something, we rename those tables when
upgrading to match what we have in maintenance/postgres/tables.sql

And by the way, tell installer not to check for "user" table, since most
PostgreSQL users will have "mwuser" instead. Picking "archive" instead.

Patchset2: wrapped commit message at 72 chars

Change-Id: Ic874e92bb1adda3430d3292423d4f3617c25456c
This commit is contained in:
Marcin Cieślak 2012-03-14 20:20:53 +00:00 committed by Antoine Musso
parent f8dc2abffc
commit 556c5cf464
3 changed files with 17 additions and 6 deletions

View file

@ -708,14 +708,19 @@ class DatabasePostgres extends DatabaseBase {
# Replace reserved words with better ones
switch( $name ) {
case 'user':
return 'mwuser';
return $this->realTableName( 'mwuser', $format );
case 'text':
return 'pagecontent';
return $this->realTableName( 'pagecontent', $format );
default:
return parent::tableName( $name, $format );
return $this->realTableName( $name, $format );
}
}
/* Don't cheat on installer */
function realTableName( $name, $format = 'quoted' ) {
return parent::tableName( $name, $format );
}
/**
* Return the next in a sequence, save the value for retrieval via insertId()
* @return null
@ -990,7 +995,7 @@ class DatabasePostgres extends DatabaseBase {
if ( !$schema ) {
$schema = $this->getCoreSchema();
}
$table = $this->tableName( $table, 'raw' );
$table = $this->realTableName( $table, 'raw' );
$etable = $this->addQuotes( $table );
$eschema = $this->addQuotes( $schema );
$SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "

View file

@ -158,7 +158,7 @@ abstract class DatabaseInstaller {
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
if( $this->db->tableExists( 'user', __METHOD__ ) ) {
if( $this->db->tableExists( 'archive', __METHOD__ ) ) {
$status->warning( 'config-install-tables-exist' );
$this->enableLB();
return $status;

View file

@ -27,6 +27,11 @@ class PostgresUpdater extends DatabaseUpdater {
*/
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' ),
@ -406,7 +411,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" );
}
}