Files
fizzy/db/migrate/20260212102026_fix_notifications_ordered_index.rb
Stanko K.R. 22276a25c8 Index notifications on updated_at
As we now update notifications with unread counts we sort them by the
time they were updated instead of when they were created. To keep that
performant we also have to change the previous indices that used
created_at to use updated_at.
2026-02-12 11:36:46 +01:00

9 lines
379 B
Ruby

class FixNotificationsOrderedIndex < ActiveRecord::Migration[8.2]
def change
add_index :notifications, [ :user_id, :read_at, :updated_at ],
order: { read_at: :desc, updated_at: :desc },
name: "index_notifications_on_user_id_and_read_at_and_updated_at"
remove_index :notifications, name: "index_notifications_on_user_id_and_read_at_and_created_at"
end
end