DEV: `down` migration for `add_trigger_on_field_default_value_to_topic_tags_changed_trigger` migration

This commit is contained in:
Gabriel Grubba 2024-12-20 09:37:08 -03:00
parent 5e82f963c6
commit dec0fbae61
No known key found for this signature in database
GPG Key ID: 5FE41764F62D556C
1 changed files with 15 additions and 1 deletions

View File

@ -26,7 +26,21 @@ class AddTriggerOnFieldDefaultValueToTopicTagsChangedTrigger < ActiveRecord::Mig
)
end
end
def down
raise ActiveRecord::IrreversibleMigration
trigger_on_fields = DB.query <<~SQL
SELECT discourse_automation_fields.*
FROM discourse_automation_fields
JOIN discourse_automation_automations
ON discourse_automation_fields.automation_id = discourse_automation_automations.id
WHERE discourse_automation_automations.trigger = 'topic_tags_changed'
AND discourse_automation_automations.enabled = TRUE
AND discourse_automation_fields.name = 'trigger_on'
SQL
trigger_on_fields.each { |field| DB.exec(<<~SQL, field_id: field.id) }
DELETE FROM discourse_automation_fields
WHERE id = :field_id
SQL
end
end