From dec0fbae613cf8372bbfc1a61fa7396560555895 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba Date: Fri, 20 Dec 2024 09:37:08 -0300 Subject: [PATCH] DEV: `down` migration for `add_trigger_on_field_default_value_to_topic_tags_changed_trigger` migration --- ...efault_value_to_topic_tags_changed_trigger.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/automation/db/migrate/20241219222326_add_trigger_on_field_default_value_to_topic_tags_changed_trigger.rb b/plugins/automation/db/migrate/20241219222326_add_trigger_on_field_default_value_to_topic_tags_changed_trigger.rb index a4a9dca95f8..ffd4362728c 100644 --- a/plugins/automation/db/migrate/20241219222326_add_trigger_on_field_default_value_to_topic_tags_changed_trigger.rb +++ b/plugins/automation/db/migrate/20241219222326_add_trigger_on_field_default_value_to_topic_tags_changed_trigger.rb @@ -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