DEV: migration to add trigger_on field default value to topic_tags_changed_trigger
This commit is contained in:
parent
678b645145
commit
5e82f963c6
|
@ -0,0 +1,32 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
class AddTriggerOnFieldDefaultValueToTopicTagsChangedTrigger < ActiveRecord::Migration[7.2]
|
||||||
|
def up
|
||||||
|
create_automation_field = <<~SQL
|
||||||
|
INSERT INTO discourse_automation_fields (automation_id, name, component, metadata, target, created_at, updated_at)
|
||||||
|
VALUES (:automation_id, 'trigger_on', 'choices', :metadata, 'script', NOW(), NOW())
|
||||||
|
SQL
|
||||||
|
|
||||||
|
topic_tags_changed_enabled_automations_without_trigger_on_field = DB.query <<~SQL
|
||||||
|
SELECT discourse_automation_automations.*
|
||||||
|
FROM discourse_automation_automations
|
||||||
|
WHERE discourse_automation_automations.trigger = 'topic_tags_changed'
|
||||||
|
AND discourse_automation_automations.enabled = TRUE
|
||||||
|
AND NOT EXISTS
|
||||||
|
(SELECT 1
|
||||||
|
FROM discourse_automation_fields
|
||||||
|
WHERE automation_id = discourse_automation_automations.id
|
||||||
|
AND name = 'trigger_on')
|
||||||
|
SQL
|
||||||
|
|
||||||
|
topic_tags_changed_enabled_automations_without_trigger_on_field.each do |automation|
|
||||||
|
DB.exec(
|
||||||
|
create_automation_field,
|
||||||
|
automation_id: automation.id,
|
||||||
|
metadata: { "value" => "tags_added_or_removed" }.to_json,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue