From: Timo Tijhof Date: Fri, 24 Feb 2017 03:39:03 +0000 (-0800) Subject: installer: Fix "relation 'user' does not exist" error for Postgres X-Git-Tag: 1.31.0-rc.0~3986 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=9b0cfff5aa4d6cf1ba23e0a333e081a928a720ab;p=lhc%2Fweb%2Fwiklou.git installer: Fix "relation 'user' does not exist" error for Postgres 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 --- diff --git a/includes/db/MWLBFactory.php b/includes/db/MWLBFactory.php index 0186222f06..fe063f20b1 100644 --- a/includes/db/MWLBFactory.php +++ b/includes/db/MWLBFactory.php @@ -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 diff --git a/includes/installer/MssqlInstaller.php b/includes/installer/MssqlInstaller.php index 5e8ed3fb8c..d6efeb2deb 100644 --- a/includes/installer/MssqlInstaller.php +++ b/includes/installer/MssqlInstaller.php @@ -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, diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 6dfa28b21c..906768f489 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -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() );