2019-12-12 06:00:28 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class EnsuresUniqueAcceptedAnswerPostId < ActiveRecord::Migration[5.2]
|
|
|
|
def change
|
|
|
|
execute <<~SQL
|
|
|
|
DELETE FROM topic_custom_fields AS tcf1
|
|
|
|
USING topic_custom_fields AS tcf2
|
|
|
|
WHERE tcf1.id > tcf2.id AND
|
|
|
|
tcf1.topic_id = tcf2.topic_id AND
|
|
|
|
tcf1.name = tcf2.name AND
|
|
|
|
tcf1.name = 'accepted_answer_post_id'
|
|
|
|
SQL
|
|
|
|
|
|
|
|
add_index :topic_custom_fields,
|
2022-12-23 15:36:08 -05:00
|
|
|
:topic_id,
|
|
|
|
name: :idx_topic_custom_fields_accepted_answer,
|
|
|
|
unique: true,
|
|
|
|
where: "name = 'accepted_answer_post_id'"
|
2019-12-12 06:00:28 -05:00
|
|
|
end
|
|
|
|
end
|