mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: Promote historic post_deploy migrations for core plugins. (#30987)
This commit promotes all post_deploy migrations which existed in Discourse v3.3.0 (timestamp <= 20240717053710)
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SwitchTopicAutomationCustomFieldsToJson < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
results = DB.query(<<~SQL)
|
||||
SELECT topic_id, ARRAY_AGG(value) AS values
|
||||
FROM topic_custom_fields
|
||||
WHERE name = 'discourse_automation_ids'
|
||||
GROUP BY topic_id
|
||||
SQL
|
||||
|
||||
execute(<<~SQL)
|
||||
DELETE FROM topic_custom_fields
|
||||
WHERE name = 'discourse_automation_ids'
|
||||
SQL
|
||||
|
||||
results.each do |row|
|
||||
parsed = row.values.map(&:to_i).uniq
|
||||
|
||||
DB.exec(<<~SQL, topic_id: row.topic_id, value: parsed.to_json)
|
||||
INSERT INTO topic_custom_fields
|
||||
(topic_id, name, value, created_at, updated_at)
|
||||
VALUES
|
||||
(:topic_id, 'discourse_automation_ids_json', :value, NOW(), NOW())
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SwitchUserAutomationCustomFieldsToJson < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
results = DB.query(<<~SQL)
|
||||
SELECT user_id, ARRAY_AGG(value) AS values
|
||||
FROM user_custom_fields
|
||||
WHERE name = 'discourse_automation_ids'
|
||||
GROUP BY user_id
|
||||
SQL
|
||||
|
||||
execute(<<~SQL)
|
||||
DELETE FROM user_custom_fields
|
||||
WHERE name = 'discourse_automation_ids'
|
||||
SQL
|
||||
|
||||
results.each do |row|
|
||||
parsed = row.values.map(&:to_i).uniq
|
||||
|
||||
DB.exec(<<~SQL, user_id: row.user_id, value: parsed.to_json)
|
||||
INSERT INTO user_custom_fields
|
||||
(user_id, name, value, created_at, updated_at)
|
||||
VALUES
|
||||
(:user_id, 'discourse_automation_ids_json', :value, NOW(), NOW())
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SwitchTopicAutomationTriggeredIdsCustomFieldsToJson < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
results = DB.query(<<~SQL)
|
||||
SELECT topic_id, ARRAY_AGG(value) AS values
|
||||
FROM topic_custom_fields
|
||||
WHERE name = 'auto_responder_triggered_ids'
|
||||
GROUP BY topic_id
|
||||
SQL
|
||||
|
||||
execute(<<~SQL)
|
||||
DELETE FROM topic_custom_fields
|
||||
WHERE name = 'auto_responder_triggered_ids'
|
||||
SQL
|
||||
|
||||
results.each do |row|
|
||||
parsed = row.values.map(&:to_i).uniq
|
||||
|
||||
DB.exec(<<~SQL, topic_id: row.topic_id, value: parsed.to_json)
|
||||
INSERT INTO topic_custom_fields
|
||||
(topic_id, name, value, created_at, updated_at)
|
||||
VALUES
|
||||
(:topic_id, 'auto_responder_triggered_ids_json', :value, NOW(), NOW())
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DropAutomationIdsCustomFieldIndexes < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
remove_index :topic_custom_fields,
|
||||
name: :idx_topic_custom_fields_discourse_automation_unique_id_partial,
|
||||
if_exists: true
|
||||
remove_index :user_custom_fields,
|
||||
name: :idx_user_custom_fields_discourse_automation_unique_id_partial,
|
||||
if_exists: true
|
||||
remove_index :post_custom_fields,
|
||||
name: :idx_post_custom_fields_discourse_automation_unique_id_partial,
|
||||
if_exists: true
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user