Handling Deprecated Enum Values Safely

If your application is evolving, you might need to deprecate old enum values while keeping the database intact.

Marking Old Enum Values as Deprecated

Instead of removing an enum immediately, mark it deprecated and prevent new records from using it:·

class User < ApplicationRecord
  enum :status, { active: 0, inactive: 1, banned: 2, deprecated_old_status: 3 }

  validates :status, exclusion: { in: [:deprecated_old_status] }
end

Now, old records can still exist in the database, but new users cannot be assigned deprecated_old_status.