Rename "user" and "text" when upgrading on PostgreSQL
authorMarcin Cieślak <saper@users.mediawiki.org>
Wed, 14 Mar 2012 20:20:53 +0000 (20:20 +0000)
committerAntoine Musso <hashar@free.fr>
Sat, 24 Mar 2012 08:10:59 +0000 (09:10 +0100)
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

includes/db/DatabasePostgres.php
includes/installer/DatabaseInstaller.php
includes/installer/PostgresUpdater.php

index 6452f54..e2b38f5 100644 (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 "
index 14604c1..046fa16 100644 (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;
index d4412cb..6b3cb51 100644 (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" );
                }
        }