#84 マイグレ修正
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user