docbrown/db/migrate/20190531094609_add_unique_user_id_notifications_index.rb
Anna Buianova 2c05bbc0c1 Change notifications unique indexes #2525 (#3012)
* Notifications unique indexes that take null values into account

* Specify import options for reaction notifications according to the indexes

* Fix specs: notifications have either user_id or organization_id

* Create notifications indexes concurrently
2019-06-13 15:17:50 -04:00

16 lines
650 B
Ruby

class AddUniqueUserIdNotificationsIndex < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def change
add_index :notifications, %i[user_id notifiable_id notifiable_type action],
where: "action IS NOT NULL",
unique: true,
name: "index_notifications_on_user_notifiable_and_action_not_null",
algorithm: :concurrently
add_index :notifications, %i[user_id notifiable_id notifiable_type],
where: "action IS NULL",
unique: true,
name: "index_notifications_on_user_notifiable_action_is_null",
algorithm: :concurrently
end
end