Merge branch 'fix-broken-mysql-migration' into 'master'

Fix broken migration in MySQL

`keys` is a reserved name in MySQL, so if this migration actually attempted to remove any duplicate keys it would fail.

Closes #19344

See merge request !5005
This commit is contained in:
Robert Speicher 2016-07-08 16:11:45 +00:00
commit e82c72d1f1
1 changed files with 2 additions and 2 deletions

View File

@ -4,12 +4,12 @@ class RemoveDuplicatedKeys < ActiveRecord::Migration
select_all("SELECT fingerprint FROM #{quote_table_name(:keys)} GROUP BY fingerprint HAVING COUNT(*) > 1").each do |row| select_all("SELECT fingerprint FROM #{quote_table_name(:keys)} GROUP BY fingerprint HAVING COUNT(*) > 1").each do |row|
fingerprint = connection.quote(row['fingerprint']) fingerprint = connection.quote(row['fingerprint'])
execute(%Q{ execute(%Q{
DELETE FROM keys DELETE FROM #{quote_table_name(:keys)}
WHERE fingerprint = #{fingerprint} WHERE fingerprint = #{fingerprint}
AND id != ( AND id != (
SELECT id FROM ( SELECT id FROM (
SELECT max(id) AS id SELECT max(id) AS id
FROM keys FROM #{quote_table_name(:keys)}
WHERE fingerprint = #{fingerprint} WHERE fingerprint = #{fingerprint}
) max_ids ) max_ids
) )