mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 18:29:52 +01:00
20 lines
548 B
Ruby
20 lines
548 B
Ruby
# frozen_string_literal: true
|
|
|
|
class RemoveDuplicateReactions < ActiveRecord::Migration[7.0]
|
|
def up
|
|
execute <<~SQUIRREL
|
|
DELETE FROM reactions
|
|
WHERE id IN (
|
|
SELECT id FROM (
|
|
SELECT id, row_number() over (PARTITION BY parent_type, parent_id, user_id ORDER BY id) AS row_number FROM reactions
|
|
)s WHERE row_number >= 2
|
|
)
|
|
SQUIRREL
|
|
|
|
add_index :reactions, %i[parent_type parent_id user_id], unique: true
|
|
end
|
|
|
|
def down
|
|
remove_index :reactions, %i[parent_type parent_id user_id]
|
|
end
|
|
end
|