Make sure database update succeeds from older database versions too.
authorPurdea Andrei <andrei@purdea.ro>
Sun, 13 Jan 2019 04:14:56 +0000 (06:14 +0200)
committerPurdea Andrei <andrei@purdea.ro>
Sun, 13 Jan 2019 04:29:37 +0000 (06:29 +0200)
commit68c298ed05ef7b5be8099ff272e6dea20d00e42b
tree380067458edc4f0702aba5d496920a41dde7bfbd
parented1adb77fa5504a4d1b41a8881926c57386ddd8e
Make sure database update succeeds from older database versions too.

Fixes the following error message when updating from an older database.
Renaming index il_from into PRIMARY to table imagelinks ...[7dbf1dd298ecf39128707744] [no req]   Wikimedia\Rdbms\DBQueryError from line 1149 of /home/zok/mediawiki-1.30.1/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: INSERT INTO imagelinks_tmp
 SELECT * FROM imagelinks

Function: Wikimedia\Rdbms\Database::sourceFile( /home/zok/mediawiki-1.30.1/maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql )
Error: 19 UNIQUE constraint failed: imagelinks_tmp.il_from, imagelinks_tmp.il_to

Explanation:
the "imagelinks" table used to have two fields: il_from and il_to.
At one point during the development of mediawiki a new field has been
added called il_from_namespace. This new filed is the second column
if the database is created from scratch, however if the database is
updated from an older version then the il_from_namespace column becomes
the 3rd column.

That means that some of the older databases will have the columns in the
following order:
(1) il_from, il_from_namespace, il_to
while some older ones, which have been updated will have the following
order:
(2) il_from, il_to, il_from_namespace

This shouldn't matter much, except the file modified in this commit
copies records from one table to another using the INSERT INTO ... SELECT
command without explicitly listing the column names.
The newly created table has the (1) order, but the source table
might sometimes have the (2) order.

Explicitly listing the column names solves all the issues.

Change-Id: I222b171495d14ae45339c4679e263f0ab610e826
maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql