From 68c298ed05ef7b5be8099ff272e6dea20d00e42b Mon Sep 17 00:00:00 2001 From: Purdea Andrei Date: Sun, 13 Jan 2019 06:14:56 +0200 Subject: [PATCH] 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql b/maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql index b48bea5323..3a37f415e0 100644 --- a/maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql +++ b/maintenance/sqlite/archives/patch-imagelinks-fix-pk.sql @@ -11,8 +11,8 @@ CREATE TABLE /*_*/imagelinks_tmp ( PRIMARY KEY (il_from,il_to) ) /*$wgDBTableOptions*/; -INSERT INTO /*_*/imagelinks_tmp - SELECT * FROM /*_*/imagelinks; +INSERT INTO /*_*/imagelinks_tmp (il_from, il_from_namespace, il_to) + SELECT il_from, il_from_namespace, il_to FROM /*_*/imagelinks; DROP TABLE /*_*/imagelinks; -- 2.20.1