Browse Source

#84 マイグレ修正

feature/084
みてるぞ 2 days ago
parent
commit
acb14be38b
1 changed files with 19 additions and 1 deletions
  1. +19
    -1
      backend/db/migrate/20251011200300_add_discard_to_post_tags.rb

+ 19
- 1
backend/db/migrate/20251011200300_add_discard_to_post_tags.rb View File

@@ -1,5 +1,19 @@
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_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

Loading…
Cancel
Save