class Cleanup::MarkOldNotifications
def call(before: 90.days.ago)
Notification.where('created_at < ?', before).update_all(deleted_at: Time.current)
end
end
class Cleanup::SweepNotificationsJob < ApplicationJob
queue_as :maintenance
def perform(limit: 10_000)
Notification.where.not(deleted_at: nil).order(deleted_at: :asc).limit(limit).delete_all
end
end
Direct deletes can be risky and slow. Mark records for deletion, then sweep in batches in a maintenance job. This gives you observability and a rollback window.