mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-19 04:26:03 +01:00
Merge pull request #1532 from Retrospring/fix/deduplicate-reactions
This commit is contained in:
commit
855d0fa867
2 changed files with 22 additions and 1 deletions
20
db/migrate/20231220100445_remove_duplicate_reactions.rb
Normal file
20
db/migrate/20231220100445_remove_duplicate_reactions.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# 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
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_12_09_212629) do
|
ActiveRecord::Schema[7.0].define(version: 2023_12_20_100445) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_12_09_212629) do
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["parent_id", "parent_type"], name: "index_reactions_on_parent_id_and_parent_type"
|
t.index ["parent_id", "parent_type"], name: "index_reactions_on_parent_id_and_parent_type"
|
||||||
|
t.index ["parent_type", "parent_id", "user_id"], name: "index_reactions_on_parent_type_and_parent_id_and_user_id", unique: true
|
||||||
t.index ["user_id", "created_at"], name: "index_reactions_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_reactions_on_user_id_and_created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue