I ran into this problem trying to update shared tables with update.php, and after digging deep, I finally found out that Database::tableName returns the table name prefixed by the database it resides in when that table is shared. MysqlDatabaseBase::tableExists places that directly in the SQL query. This way tableExists reports that the table does not exist while running a SHOW TABLES; query on the shared database reports the table as existing. Manually inputting the SQL query in the database confirms that the query returns 0 results. The reason update.php fails, is because it relies on the tableExists method to check if a table exists, and with that knowledge can determine if it should create the table, or skip the patching process. So even if update.php ran without throwing an error, it still has not patched the global tables. The only indication to this is a message mentioning that TABLENAME table does not exist, skipping [...] patch.
Environment
- MediaWiki-Vagrant
- MySQL
- MediaWiki 1.30 - master branch
Example
Table name: user_properties
Database name: wiki
Call to Database::tableName: $db->tableName( 'user_properties', 'raw' );
Output from Database::tableName: wiki.user_properties
SQL query sent to the database: SHOW TABLES LIKE 'wiki.user\_properties';
Reproducing (on MediaWiki-Vagrant)
Set $wgSharedDB to wiki (MediaWiki-Vagrant's default wiki database) and try to run mwscript update.php --doshared
Solution
Staring at https://dev.mysql.com/doc/refman/5.7/en/show-tables.html I'm assuming the query should instead be SHOW TABLES FROM wiki LIKE 'user\_properties';