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)
committerReedy <reedy@wikimedia.org>
Sun, 30 Jun 2019 21:29:12 +0000 (21:29 +0000)
commitab3cc3805f036df5a5e175cde5644cfa760a78e6
treeacfa813f88009205c3cb11f732333383aef83f50
parent801a8bdaa38cea5ff4db0440c82e9eb83e083772
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
(cherry picked from commit 68c298ed05ef7b5be8099ff272e6dea20d00e42b)
maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql