mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-05-05 16:07:29 +00:00
DEV: Move the post and topic custom fields into a table
This commit is contained in:
parent
e82c6ae1ca
commit
65c972c18f
@ -0,0 +1,41 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
#
|
||||||
|
class CopySolvedTopicCustomFieldToDiscourseSolvedTopics < ActiveRecord::Migration[7.2]
|
||||||
|
def up
|
||||||
|
create_table :discourse_solved_topics do |t|
|
||||||
|
t.integer :topic_id, null: false
|
||||||
|
t.integer :answer_post_id, null: false
|
||||||
|
t.integer :accepter_user_id
|
||||||
|
t.integer :topic_timer_id
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
INSERT INTO discourse_solved_topics (
|
||||||
|
topic_id,
|
||||||
|
answer_post_id,
|
||||||
|
topic_timer_id,
|
||||||
|
accepter_user_id,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
) SELECT DISTINCT
|
||||||
|
tc.topic_id,
|
||||||
|
CAST(tc.value AS INTEGER),
|
||||||
|
CAST(tc2.value AS INTEGER),
|
||||||
|
ua.acting_user_id,
|
||||||
|
tc.created_at,
|
||||||
|
tc.updated_at
|
||||||
|
FROM topic_custom_fields tc
|
||||||
|
LEFT JOIN topic_custom_fields tc2
|
||||||
|
ON tc2.topic_id = tc.topic_id AND tc2.name = 'solved_auto_close_topic_timer_id'
|
||||||
|
LEFT JOIN user_actions ua
|
||||||
|
ON ua.target_topic_id = tc.topic_id
|
||||||
|
WHERE tc.name = 'accepted_answer_post_id'
|
||||||
|
AND ua.action_type = #{UserAction::SOLVED}
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
#
|
||||||
|
class AddIndexForDiscourseSolvedTopics < ActiveRecord::Migration[7.2]
|
||||||
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_index :discourse_solved_topics, :topic_id, unique: true, algorithm: :concurrently
|
||||||
|
add_index :discourse_solved_topics, :answer_post_id, unique: true, algorithm: :concurrently
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user