installer: Fix "relation 'user' does not exist" error for Postgres
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 24 Feb 2017 03:39:03 +0000 (19:39 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 24 Feb 2017 03:39:03 +0000 (19:39 -0800)
On Travis CI, the Postgres build has been failing very early on
in the installer (before phpunit) due to a database error:

> Creating administrator user account.. DBQueryError at Database.php:1059
> Query: SELECT user_id FROM "user" WHERE user_name = 'Admin' LIMIT 1
> Function: User::idForName
> Error: 42P01 ERROR:  relation "user" does not exist
> LINE 1: SELECT /* User::idForName  */ user_id FROM "user" ...

This is because the installer makes its own Database object without
involving ServiceWiring or MWLBFactory, which means wgDBport and
(more importantly) 'keywordTableMap' don't get applied.

While keywordTableMap doesn't matter during the database installation,
after the installer is done updating GlobalVarConfig and resetting
MediaWikiServices, DatabaseInstaller::enableLB takes that homemade
connection and injects it into MediaWikiServices by redefining
the 'DBLoadBalancerFactory' service. Which then affects all use
of wfGetDB(), such as from User::idForName().

Bug: T30162
Bug: T75174
Bug: T75176
Change-Id: I7af58c4beffc4908a93c0c1d8ab1aec9d4ec57c6

includes/db/MWLBFactory.php
includes/installer/MssqlInstaller.php
includes/installer/PostgresInstaller.php

index 0186222..fe063f2 100644 (file)
@@ -59,6 +59,9 @@ abstract class MWLBFactory {
                        'readOnlyReason' => wfConfiguredReadOnlyReason(),
                ];
 
+               // When making changes here, remember to also specify MediaWiki-specific options
+               // for Database classes in the relevant Installer subclass.
+               // Such as MysqlInstaller::openConnection and PostgresInstaller::openConnectionWithParams.
                if ( $lbConf['class'] === 'LBFactorySimple' ) {
                        if ( isset( $lbConf['servers'] ) ) {
                                // Server array is already explicitly configured; leave alone
index 5e8ed3f..d6efeb2 100644 (file)
@@ -214,6 +214,7 @@ class MssqlInstaller extends DatabaseInstaller {
                try {
                        $db = Database::factory( 'mssql', [
                                'host' => $this->getVar( 'wgDBserver' ),
+                               'port' => $this->getVar( 'wgDBport' ),
                                'user' => $user,
                                'password' => $password,
                                'dbname' => false,
index 6dfa28b..906768f 100644 (file)
@@ -156,10 +156,13 @@ class PostgresInstaller extends DatabaseInstaller {
                try {
                        $db = Database::factory( 'postgres', [
                                'host' => $this->getVar( 'wgDBserver' ),
+                               'port' => $this->getVar( 'wgDBport' ),
                                'user' => $user,
                                'password' => $password,
                                'dbname' => $dbName,
-                               'schema' => $schema ] );
+                               'schema' => $schema,
+                               'keywordTableMap' => [ 'user' => 'mwuser', 'text' => 'pagecontent' ],
+                       ] );
                        $status->value = $db;
                } catch ( DBConnectionError $e ) {
                        $status->fatal( 'config-connection-error', $e->getMessage() );