# Migration corrigida da Fase 2:
# - Timestamp no padrão (roda DEPOIS da create_users)
# - Removidos pin_acesso e ativo (já existem como pin_code e ativo na create_users)
# - Mantidos apenas os campos Devise trackable + lockable
class AddDeviseTrackableToUsers < ActiveRecord::Migration[7.1]
  def change
    # Trackable
    add_column :users, :sign_in_count,      :integer, default: 0, null: false
    add_column :users, :current_sign_in_at, :datetime
    add_column :users, :last_sign_in_at,    :datetime
    add_column :users, :current_sign_in_ip, :string
    add_column :users, :last_sign_in_ip,    :string

    # Lockable
    add_column :users, :failed_attempts, :integer, default: 0, null: false
    add_column :users, :unlock_token,    :string
    add_column :users, :locked_at,       :datetime
    add_index  :users, :unlock_token, unique: true
  end
end
