FIX: check for existing translation keys before replacing blocked with silenced

This commit is contained in:
Arpit Jalan 2017-12-28 18:48:25 +05:30
parent 5ca558c7c5
commit 84026ad1fd

View File

@ -1,8 +1,17 @@
class ReplaceBlockedSilenceTranslation < ActiveRecord::Migration[5.1]
def change
execute <<~SQL
UPDATE translation_overrides SET translation_key = 'system_messages.silenced_by_staff.subject_template' WHERE translation_key = 'system_messages.blocked_by_staff.subject_template';
UPDATE translation_overrides SET translation_key = 'system_messages.silenced_by_staff.text_body_template' WHERE translation_key = 'system_messages.blocked_by_staff.text_body_template';
UPDATE translation_overrides
SET translation_key = 'system_messages.silenced_by_staff.subject_template'
WHERE translation_key = 'system_messages.blocked_by_staff.subject_template'
AND NOT EXISTS (SELECT 1 FROM translation_overrides WHERE translation_key = 'system_messages.silenced_by_staff.subject_template');
SQL
execute <<~SQL
UPDATE translation_overrides
SET translation_key = 'system_messages.silenced_by_staff.text_body_template'
WHERE translation_key = 'system_messages.blocked_by_staff.text_body_template'
AND NOT EXISTS (SELECT 1 FROM translation_overrides WHERE translation_key = 'system_messages.silenced_by_staff.text_body_template');
SQL
end
end