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

マージ済み
みてるぞ が 5 個のコミットを feature/084 から main へマージ 2025-12-13 16:34:47 +09:00
コミット acb14be38b の変更だけを表示してゐます - すべてのコミットを表示
+19 -1
ファイルの表示
@@ -1,5 +1,19 @@
class AddDiscardToPostTags < ActiveRecord::Migration[8.0]
def change
def up
miteruzo がこの会話を解決済みにしました 古い内容
古い内容
レビュー

change ではなく up にしたい.
down は設けず,不可逆な作りにしたはぅが安心.

`change` ではなく `up` にしたい. `down` は設けず,不可逆な作りにしたはぅが安心.
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_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, [:tag_id, :discarded_at]
end
def down
raise ActiveRecord::IrreversibleMigration, '戻せません.'
end
end