Using Composite Indexes with Enums

In some cases, indexing an enum column alone is not enough. You might need composite indexes (multiple columns indexed together).

For example, if status and role are often queried together, a composite index can optimize performance:

class AddCompositeIndexToUsers < ActiveRecord::Migration[7.0]
  def change
    add_index :users, [:status, :role]
  end
end

Now, queries like this will be much faster:

User.where(status: :active, role: :admin)