FIX: Incorrect DB query for AddUploadsToCategories migration.

This is a regression as a result of 7896c74c2b. Most instances would have ran the migrations and some might have run this migration with the incorrect query. Impact of this is small for now but I'm fixing this for correctness purposes.
This commit is contained in:
Guo Xiang Tan
2019-04-26 10:25:55 +08:00
committed by Guo Xiang Tan
parent 96360a779f
commit c9f6beba05
2 changed files with 52 additions and 8 deletions

View File

@@ -4,19 +4,19 @@ class AddUploadsToCategories < ActiveRecord::Migration[4.2]
add_column :categories, :uploaded_background_id, :integer, index: true
execute <<~SQL
UPDATE categories
UPDATE categories c1
SET uploaded_logo_id = u.id
FROM categories c
LEFT JOIN uploads u ON u.url = c.logo_url
WHERE u.url IS NOT NULL
FROM categories c2
INNER JOIN uploads u ON u.url = c2.logo_url
WHERE c1.id = c2.id
SQL
execute <<~SQL
UPDATE categories
UPDATE categories c1
SET uploaded_background_id = u.id
FROM categories c
LEFT JOIN uploads u ON u.url = c.background_url
WHERE u.url IS NOT NULL
FROM categories c2
INNER JOIN uploads u ON u.url = c2.background_url
WHERE c1.id = c2.id
SQL
end
end