remove unused post/topic custom fields

This commit is contained in:
Lhc_fl 2024-09-05 19:35:03 +08:00
parent 150f7f4a35
commit 56f8327234
No known key found for this signature in database
GPG Key ID: DB9FFA0D3F210F60
1 changed files with 42 additions and 5 deletions

View File

@ -36,14 +36,51 @@ class MoveSolvedTopicCustomFieldToDiscourseSolvedSolutions < ActiveRecord::Migra
AND ua.action_type = #{UserAction::SOLVED}
SQL
# execute <<-SQL
# DELETE FROM post_custom_fields
# WHERE name = 'is_accepted_answer'
# SQL
execute <<-SQL
DELETE FROM post_custom_fields
WHERE name = 'is_accepted_answer'
SQL
execute <<-SQL
DELETE FROM topic_custom_fields
WHERE name = 'solved_auto_close_topic_timer_id'
SQL
end
def down
# raise ActiveRecord::IrreversibleMigration
execute <<-SQL
INSERT INTO topic_custom_fields (
topic_id,
name,
value,
created_at,
updated_at
) SELECT DISTINCT
topic_id,
'solved_auto_close_topic_timer_id',
CAST(topic_timer_id AS TEXT),
created_at,
updated_at
FROM discourse_solved_solutions tc
WHERE tc.topic_timer_id IS NOT NULL
SQL
execute <<-SQL
INSERT INTO post_custom_fields (
post_id,
name,
value,
created_at,
updated_at
) SELECT DISTINCT
answer_post_id,
'is_accepted_answer',
'true',
created_at,
updated_at
FROM discourse_solved_solutions
SQL
remove_index :discourse_solved_solutions, :topic_id
remove_index :discourse_solved_solutions, :answer_post_id