Page MenuHomePhabricator

The second execution of install.php in 1.36.0 tries to create MediaWiki tables and fails
Closed, ResolvedPublic

Description

The behavior of install.php is changed in MediaWiki 1.36.0 and it does not seem to be intended.

Expected(previous) behavior

The second execution of install.php after removing LocalSettings.php is idempotent and its exit code is 0.

Actual behavior

"Table 'user' already exists" DBQueryError is thrown and the exit code is 1.

Reproduction steps
  1. Execute install.php.
  2. Remove LocalSettings.php generated as the result of the previous step.
  3. Execute install.php again.
Log
1.36.0
$ php /srv/www/maintenance/install.php --dbtype mysql --dbserver mysql --dbuser DB_USERNAME --dbpass DB_PASSWORD --dbname database --installdbuser DB_USERNAME --installdbpass DB_PASSWORD --pass 'admin_password_please_change' 'MyWiki' Admin
PHP 7.4.16 is installed.
Found ImageMagick: /usr/bin/convert. Image thumbnailing will be enabled if you enable uploads.
Found the Git version control software: /usr/bin/git.
Using server name "http://localhost".
Warning: No --scriptpath specified, using default: /wiki.
Using server URL "http://localhost/wiki".
Warning: Your default directory for uploads (/srv/www/images/) is not checked for vulnerability to arbitrary script execution during the CLI install.
Using the PHP intl extension for Unicode normalization.
The environment has been checked. You can install MediaWiki.
Setting up database
done
Creating tables, step one
done
Creating database user
done
Creating tables, step two
done
Populating default interwiki table
done
Initializing statistics
done
Generating secret keys
done
Prevent running unneeded updates
done
Restoring mediawiki services
done
Creating administrator user account
done
Creating main page with default content
done
Database was successfully set up
MediaWiki has been successfully installed. You can now visit <http://localhost/wiki> to view your wiki. If you have questions, check out our frequently asked questions list: <https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ> or use one of the support forums linked on that page.
$ rm LocalSettings.php 
$ php /srv/www/maintenance/install.php --dbtype mysql --dbserver mysql --dbuser DB_USERNAME --dbpass DB_PASSWORD --dbname database --installdbuser DB_USERNAME --installdbpass DB_PASSWORD --pass 'admin_password_please_change' 'MyWiki' Admin
PHP 7.4.16 is installed.
Found ImageMagick: /usr/bin/convert. Image thumbnailing will be enabled if you enable uploads.
Found the Git version control software: /usr/bin/git.
Using server name "http://localhost".
Warning: No --scriptpath specified, using default: /wiki.
Using server URL "http://localhost/wiki".
Warning: Your default directory for uploads (/srv/www/images/) is not checked for vulnerability to arbitrary script execution during the CLI install.
Using the PHP intl extension for Unicode normalization.
The environment has been checked. You can install MediaWiki.
Setting up database
done
Creating tables, step one
Warning: MediaWiki tables seem to already exist. Skipping creation.
done
Creating database user
done
Creating tables, step two
Wikimedia\Rdbms\DBQueryError from line 1719 of /srv/www/includes/libs/rdbms/database/Database.php: Error 1050: Table 'user' already exists (mysql)
Function: Wikimedia\Rdbms\Database::sourceFile( /srv/www/maintenance/tables.sql )
Query: CREATE TABLE `user` (
 user_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
 user_name varbinary(255) NOT NULL default '',
 user_real_name varbinary(255) NOT NULL default '',
 user_password tinyblob NOT NULL,
 user_newpassword tinyblob NOT NULL,
 user_newpass_time binary(14),
 user_email tinytext NOT NULL,
 user_touched binary(14) NOT NULL,
 user_token binary(32) NOT NULL default '',
 user_email_authenticated binary(14),
 user_email_token binary(32),
 user_email_token_expires binary(14),
 user_registration binary(14),
 user_editcount int,
 user_password_expires varbinary(14) DEFAULT NULL
 ) ENGINE=InnoDB, DEFAULT CHARSET=binary


#0 /srv/www/includes/libs/rdbms/database/Database.php(1703): Wikimedia\Rdbms\Database->getQueryException('Table 'user' al...', 1050, 'CREATE TABLE `u...', 'Wikimedia\\Rdbms...')
#1 /srv/www/includes/libs/rdbms/database/Database.php(1678): Wikimedia\Rdbms\Database->getQueryExceptionAndLog('Table 'user' al...', 1050, 'CREATE TABLE `u...', 'Wikimedia\\Rdbms...')
#2 /srv/www/includes/libs/rdbms/database/Database.php(1244): Wikimedia\Rdbms\Database->reportQueryError('Table 'user' al...', 1050, 'CREATE TABLE `u...', 'Wikimedia\\Rdbms...', false)
#3 /srv/www/includes/libs/rdbms/database/Database.php(5142): Wikimedia\Rdbms\Database->query('CREATE TABLE `u...', 'Wikimedia\\Rdbms...')
#4 /srv/www/includes/libs/rdbms/database/Database.php(5077): Wikimedia\Rdbms\Database->sourceStream(Resource id #926, NULL, NULL, 'Wikimedia\\Rdbms...', NULL)
#5 /srv/www/includes/installer/DatabaseInstaller.php(233): Wikimedia\Rdbms\Database->sourceFile('/srv/femiwiki.c...')
#6 /srv/www/includes/installer/DatabaseInstaller.php(267): DatabaseInstaller->stepApplySourceFile('getSchemaPath', 'install-manual', false)
#7 /srv/www/includes/installer/Installer.php(1723): DatabaseInstaller->createManualTables(Object(MysqlInstaller))
#8 /srv/www/includes/installer/CliInstaller.php(211): Installer->performInstallation(Array, Array)
#9 /srv/www/maintenance/install.php(142): CliInstaller->execute()
#10 /srv/www/maintenance/doMaintenance.php(112): CommandLineInstaller->execute()
#11 /srv/www/maintenance/install.php(203): require_once('/srv/femiwiki.c...')
#12 {main}
Notice: Uncommitted DB writes (transaction from DatabaseInstaller::stepApplySourceFile) in /srv/www/includes/libs/rdbms/database/Database.php on line 5605
$ echo $?
1
1.35.2
$ php /srv/www/maintenance/install.php --dbtype mysql --dbserver mysql --dbuser DB_USERNAME --dbpass DB_PASSWORD --dbname database --installdbuser DB_USERNAME --installdbpass DB_PASSWORD --pass 'admin_password_please_change' 'MyWiki' Admin
PHP 7.4.16 is installed.
Found ImageMagick: /usr/bin/convert. Image thumbnailing will be enabled if you enable uploads.
Found the Git version control software: /usr/bin/git.
Using server name "http://localhost".
Warning: No --scriptpath specified, using default: /wiki.
Using server URL "http://localhost/wiki".
Warning: Your default directory for uploads (/srv/www/images/) is not checked for vulnerability to arbitrary script execution during the CLI install.
Using the PHP intl extension for Unicode normalization.
The environment has been checked. You can install MediaWiki.
Setting up database
done
Creating tables, step one
done
Creating database user
done
Creating tables, step two
done
Populating default interwiki table
done
Initializing statistics
done
Generating secret keys
done
Prevent running unneeded updates
done
Restoring mediawiki services
done
Creating administrator user account
done
Creating main page with default content
done
Database was successfully set up
MediaWiki has been successfully installed. You can now visit <http://localhost/wiki> to view your wiki. If you have questions, check out our frequently asked questions list: <https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ> or use one of the support forums linked on that page.
$ rm LocalSettings.php 
$ php /srv/www/maintenance/install.php --dbtype mysql --dbserver mysql --dbuser DB_USERNAME --dbpass DB_PASSWORD --dbname database --installdbuser DB_USERNAME --installdbpass DB_PASSWORD --pass 'admin_password_please_change' 'MyWiki' Admin
PHP 7.4.16 is installed.
Found ImageMagick: /usr/bin/convert. Image thumbnailing will be enabled if you enable uploads.
Found the Git version control software: /usr/bin/git.
Using server name "http://localhost".
Warning: No --scriptpath specified, using default: /wiki.
Using server URL "http://localhost/wiki".
Warning: Your default directory for uploads (/srv/www/images/) is not checked for vulnerability to arbitrary script execution during the CLI install.
Using the PHP intl extension for Unicode normalization.
The environment has been checked. You can install MediaWiki.
Setting up database
done
Creating tables, step one
Warning: MediaWiki tables seem to already exist. Skipping creation.
done
Creating database user
done
Creating tables, step two
Warning: MediaWiki tables seem to already exist. Skipping creation.
done
Populating default interwiki table
Warning: The interwiki table seems to already have entries. Skipping default list.
done
Initializing statistics
done
Generating secret keys
done
Prevent running unneeded updates
done
Restoring mediawiki services
done
Creating administrator user account
done
Creating main page with default content
Main page already exists, skipping
done
Database was successfully set up
MediaWiki has been successfully installed. You can now visit <http://localhost/wiki> to view your wiki. If you have questions, check out our frequently asked questions list: <https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ> or use one of the support forums linked on that page.
$ echo $?
0

Event Timeline

correction: The warning seems to be for "Creating tables, step one". The error is thrown in step two.

Lens0021 renamed this task from The second execution of install.php in 1.36.0 tries to create MediaWiki tables and fails even if the message says the step is skipped to The second execution of install.php in 1.36.0 tries to create MediaWiki tables and fails.May 28 2021, 3:02 PM

I think this is a fallout of the Abstract Schema stuff...

The archive table moved from tables.sql (in 1.35), to tables-generated.sql (in 1.36).

	/**
	 * Create database tables from scratch from the automatically generated file
	 * @stable to override
	 *
	 * @return Status
	 */
	public function createTables() {
		return $this->stepApplySourceFile( 'getGeneratedSchemaPath', 'install', true );
	}

	/**
	 * Create database tables from scratch.
	 * @stable to override
	 *
	 * @return Status
	 */
	public function createManualTables() {
		return $this->stepApplySourceFile( 'getSchemaPath', 'install-manual', false );
	}

And if we look at the start of stepApplySourceFile

	/**
	 * Apply a SQL source file to the database as part of running an installation step.
	 *
	 * @param string $sourceFileMethod
	 * @param string $stepName
	 * @param bool $archiveTableMustNotExist
	 * @return Status
	 */
	private function stepApplySourceFile(
		$sourceFileMethod,
		$stepName,
		$archiveTableMustNotExist = false
	) {
		$status = $this->getConnection();
		if ( !$status->isOK() ) {
			return $status;
		}
		$this->db->selectDB( $this->getVar( 'wgDBname' ) );

		if ( $archiveTableMustNotExist && $this->db->tableExists( 'archive', __METHOD__ ) ) {
			$status->warning( "config-$stepName-tables-exist" );
			$this->enableLB();

			return $status;
		}

We should probably be doing an appropriate "existance" check for the tables still in tables.sql in 1.36, namely user, revision and searchindex

Reedy triaged this task as Low priority.May 28 2021, 8:53 PM

Change 697085 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_36] DatabaseInstaller.php: Only run core schema file if specified table doesn't already exist

https://gerrit.wikimedia.org/r/697085

Change 696539 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@master] DatabaseInstaller.php: Only run core schema file if specified table doesn't already exist

https://gerrit.wikimedia.org/r/696539

Change 697085 merged by jenkins-bot:

[mediawiki/core@REL1_36] DatabaseInstaller.php: Only run core schema file if specified table doesn't already exist

https://gerrit.wikimedia.org/r/697085

Change 696539 merged by jenkins-bot:

[mediawiki/core@master] DatabaseInstaller.php: Only run core schema file if specified table doesn't already exist

https://gerrit.wikimedia.org/r/696539

Lens0021 assigned this task to Reedy.