2017-08-31 00:06:56 -04:00
|
|
|
class FixSeenNotificationIds < ActiveRecord::Migration[4.2]
|
2013-08-09 12:12:56 -04:00
|
|
|
def up
|
|
|
|
|
|
|
|
# There was an error where `seen_notification_id` was being updated incorrectly.
|
|
|
|
# This tries to fix some of the bad data.
|
|
|
|
execute "UPDATE users SET
|
|
|
|
seen_notification_id = COALESCE((SELECT MAX(notifications.id)
|
|
|
|
FROM notifications
|
|
|
|
WHERE user_id = users.id AND created_at <= users.last_seen_at), 0)"
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
end
|
|
|
|
end
|