FIX: Add unique index to user_notes_count
This commit is contained in:
parent
3ed02456a6
commit
02563bdeab
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddUserNotesCountIndex < ActiveRecord::Migration[5.2]
|
||||
def up
|
||||
execute <<~SQL
|
||||
DELETE
|
||||
FROM user_custom_fields a
|
||||
USING user_custom_fields b
|
||||
WHERE a.name = 'user_notes_count'
|
||||
AND a.name = b.name
|
||||
AND a.id > b.id
|
||||
SQL
|
||||
|
||||
add_index :user_custom_fields,
|
||||
[:name, :user_id],
|
||||
unique: true,
|
||||
name: :idx_user_custom_fields_user_notes_count,
|
||||
where: "name = 'user_notes_count'"
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :user_custom_fields, name: :idx_user_custom_fields_user_notes_count
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue