Page MenuHomePhabricator

patch-cleanup-push_subscription-foreign-keys-indexes: SQL syntax error (MySQL 5.7.24)
Closed, ResolvedPublicBUG REPORT

Description

Steps to reproduce

  • Run php .\maintenance\update.php --quick (have also tried php .\maintenance\update.php --quick --force)

What happens

A SQL syntax error is returned while running patch-cleanup-push_subscription-foreign-keys-indexes.sql (Echo) — added in rECHOd35c502b60cd: schema: Drop foreign keys from table echo_push_subscription (T306473)

Running extensions/Echo/maintenance/updateEchoSchemaForSuppression.php...
...Update 'UpdateEchoSchemaForSuppression' already logged as completed. Use --force to run it again.
done.
...echo_event table does not contain event_page_namespace field.
...echo_event table does not contain event_page_title field.
...echo_notification table does not contain notification_bundle_base field.
...echo_notification table does not contain notification_bundle_display_hash field.
...echo_notification_user_hash_timestamp key doesn't exist.
...echo_push_provider table already exists.
...echo_push_subscription table already exists.
...echo_push_topic table already exists.
Modifying table echo_push_subscription...Wikimedia\Rdbms\DBQueryError from line 1748 of A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\Database.php: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS `echo_push_subscription_ibfk_1`' at line 1
Function: Wikimedia\Rdbms\Database::sourceFile( A:\wikimedia\mediawiki-local\extensions\Echo/sql/mysql/patch-cleanup-push_subscription-foreign-keys-indexes.sql )
Query: ALTER TABLE `echo_push_subscription` DROP FOREIGN KEY IF EXISTS `echo_push_subscription_ibfk_1`


#0 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\Database.php(1732): Wikimedia\Rdbms\Database->getQueryException('You have an err...', 1064, 'ALTER TABLE `ec...', 'Wikimedia\\Rdbms...')
#1 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\Database.php(1706): Wikimedia\Rdbms\Database->getQueryExceptionAndLog('You have an err...', 1064, 'ALTER TABLE `ec...', 'Wikimedia\\Rdbms...')
#2 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\Database.php(1082): Wikimedia\Rdbms\Database->reportQueryError('You have an err...', 1064, 'ALTER TABLE `ec...', 'Wikimedia\\Rdbms...', false)
#3 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\Database.php(3429): Wikimedia\Rdbms\Database->query('ALTER TABLE `ec...', 'Wikimedia\\Rdbms...')
#4 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\Database.php(3368): Wikimedia\Rdbms\Database->sourceStream(Resource id #971, NULL, NULL, 'Wikimedia\\Rdbms...', NULL)
#5 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\DBConnRef.php(109): Wikimedia\Rdbms\Database->sourceFile('A:\\wikimedia\\me...')
#6 A:\wikimedia\mediawiki-local\includes\libs\rdbms\database\DBConnRef.php(799): Wikimedia\Rdbms\DBConnRef->__call('sourceFile', Array)
#7 A:\wikimedia\mediawiki-local\includes\installer\DatabaseUpdater.php(718): Wikimedia\Rdbms\DBConnRef->sourceFile('A:\\wikimedia\\me...')
#8 A:\wikimedia\mediawiki-local\includes\installer\DatabaseUpdater.php(1034): DatabaseUpdater->applyPatch('A:\\wikimedia\\me...', true, 'Modifying table...')
#9 A:\wikimedia\mediawiki-local\includes\installer\DatabaseUpdater.php(547): DatabaseUpdater->modifyTable('echo_push_subsc...', 'A:\\wikimedia\\me...', true)
#10 A:\wikimedia\mediawiki-local\includes\installer\DatabaseUpdater.php(515): DatabaseUpdater->runUpdates(Array, true)
#11 A:\wikimedia\mediawiki-local\maintenance\update.php(202): DatabaseUpdater->doUpdates(Array)
#12 A:\wikimedia\mediawiki-local\maintenance\includes\MaintenanceRunner.php(309): UpdateMediaWiki->execute()
#13 A:\wikimedia\mediawiki-local\maintenance\doMaintenance.php(85): MediaWiki\Maintenance\MaintenanceRunner->run()
#14 A:\wikimedia\mediawiki-local\maintenance\update.php(312): require_once('A:\\wikimedia\\me...')
#15 {main}

What should have happened instead

Update runs successfully

Software

MediaWiki 	1.39.0-alpha (1862dd5)
PHP 	 	8.0.3 (apache2handler)
MySQL 	 	5.7.24
ICU 	 	68.1

Extensions

All had a git pull prior to running this.

wfLoadExtension( 'Echo' );
wfLoadExtension( 'LoginNotify' );
wfLoadExtension( 'AbuseFilter' );
wfLoadExtension( 'CheckUser' );
wfLoadExtension( 'Interwiki' );
wfLoadExtension( 'QuickSurveys' );

wfLoadExtension( 'WikiEditor' );
wfLoadExtension( 'CodeMirror' );
wfLoadExtension( 'CodeEditor' );

wfLoadExtension( 'Phonos' );

wfLoadExtension( 'EventLogging' );

wfLoadExtension( 'GlobalPreferences' );
wfLoadExtension( 'PageTriage' );

Table echo_push_subscription

CREATE TABLE `echo_push_subscription` (
	`eps_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`eps_user` INT(10) UNSIGNED NOT NULL,
	`eps_token` BLOB NOT NULL,
	`eps_token_sha256` BINARY(64) NOT NULL,
	`eps_provider` TINYINT(3) UNSIGNED NOT NULL,
	`eps_updated` TIMESTAMP NOT NULL,
	`eps_data` BLOB NULL DEFAULT NULL,
	`eps_topic` TINYINT(3) UNSIGNED NULL DEFAULT NULL,
	PRIMARY KEY (`eps_id`) USING BTREE,
	UNIQUE INDEX `eps_token_sha256` (`eps_token_sha256`) USING BTREE,
	INDEX `eps_provider` (`eps_provider`) USING BTREE,
	INDEX `eps_topic` (`eps_topic`) USING BTREE,
	INDEX `echo_push_subscription_user_id` (`eps_user`) USING BTREE,
	INDEX `echo_push_subscription_token` (`eps_token`(10)) USING BTREE,
	CONSTRAINT `echo_push_subscription_ibfk_1` FOREIGN KEY (`eps_provider`) REFERENCES `echo_push_provider` (`epp_id`) ON UPDATE RESTRICT ON DELETE RESTRICT,
	CONSTRAINT `echo_push_subscription_ibfk_2` FOREIGN KEY (`eps_topic`) REFERENCES `echo_push_topic` (`ept_id`) ON UPDATE RESTRICT ON DELETE RESTRICT
)
COLLATE='binary'
ENGINE=InnoDB;

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Ladsgroup subscribed.

Hi, DBA tag is for issues or works with databases in production. e.g. something that is assigned to the DBAs, please use the other tag for these tickets.

Hi, DBA tag is for issues or works with databases in production. e.g. something that is assigned to the DBAs, please use the other tag for these tickets.

Sorry @Ladsgroup!

Urgh it looks like DROP FOREIGN KEY IF EXISTS isn't present in MySQL / MariaDB < v10.1.4 — I know I'm using a fairly old MySQL version but I think it's still listed as supported?

We are dropping anything below 10.4 for MariaDB so that's not an issue.
Strangely, 5.7 is not EOL and we should support it but the current version is 5.7.37 and I don't know if that supports DROP FOREIGN KEY IF EXISTS or not. We can always change the alter table

(nb. I've just switched to MariaDB v10.8.3 and the patch works)

Change 821284 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/extensions/Echo@master] schema: Remove IF EXISTS from DROP FOREIGN KEY

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

The best support for mysql is to remove the EXISTS check. It seems only exists on DROP TABLE, but not on other DDL statements

Per https://www.mediawiki.org/wiki/Compatibility#Database we require 10.3 for MediaWiki 1.39, which is when this commit was added. But yeah MySQL not supporting it (even in 8.0) is a problem.

Change 821284 merged by jenkins-bot:

[mediawiki/extensions/Echo@master] schema: Remove IF EXISTS from DROP FOREIGN KEY

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