feat: 投稿とタグのリレーション・テーブルについて論理削除と履歴を追加(#84) #148

Merged
みてるぞ merged 5 commits from feature/084 into main 2025-12-13 16:34:47 +09:00
Showing only changes of commit acb14be38b - Show all commits
@@ -1,5 +1,19 @@
class AddDiscardToPostTags < ActiveRecord::Migration[8.0] class AddDiscardToPostTags < ActiveRecord::Migration[8.0]
def change def up
execute <<~SQL
DELETE
pt1
FROM
post_tags pt1
INNER JOIN
post_tags pt2
ON
pt1.post_id = pt2.post_id
AND pt1.tag_id = pt2.tag_id
AND pt1.id > pt2.id
;
SQL
add_column :post_tags, :discarded_at, :datetime add_column :post_tags, :discarded_at, :datetime
add_index :post_tags, :discarded_at add_index :post_tags, :discarded_at
@@ -15,4 +29,8 @@ class AddDiscardToPostTags < ActiveRecord::Migration[8.0]
add_index :post_tags, [:post_id, :discarded_at] add_index :post_tags, [:post_id, :discarded_at]
add_index :post_tags, [:tag_id, :discarded_at] add_index :post_tags, [:tag_id, :discarded_at]
end end
def down
raise ActiveRecord::IrreversibleMigration, '戻せません.'
end
end end