From ff101942d4d667208e50846c2e2094d8c011c1d8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 3 Dec 2021 11:43:13 +0100 Subject: [PATCH] Bug 29631: Prevent uniq_lang creation to fail We got 2 reports of this problem in the last 24h, uniq_lang unique key is failing to be created because several rows with the same (subtag, type) exist in DB. I have no idea how this is possible, but apparently it is. --- installer/data/mysql/db_revs/210600012.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/installer/data/mysql/db_revs/210600012.pl b/installer/data/mysql/db_revs/210600012.pl index fef986078be..35e5b918c8c 100755 --- a/installer/data/mysql/db_revs/210600012.pl +++ b/installer/data/mysql/db_revs/210600012.pl @@ -8,6 +8,18 @@ return { my $dbh = $args->{dbh}; if( !unique_key_exists( 'language_subtag_registry', 'uniq_lang' ) ) { + $dbh->do(q{ + DELETE a + FROM language_subtag_registry a + WHERE id IN ( + SELECT id FROM ( + SELECT MIN(id) AS id + FROM language_subtag_registry b + GROUP BY subtag, type + HAVING COUNT(*) > 1 + ) c + ); + }); $dbh->do(q{ ALTER TABLE language_subtag_registry ADD UNIQUE KEY uniq_lang (subtag, type) -- 2.25.1