class CreateUsers < ActiveRecord::Migration[7.1]
  def change
    create_table :users do |t|
      # Devise campos padrão
      t.string   :email,              null: false, default: ""
      t.string   :encrypted_password, null: false, default: ""
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at
      t.datetime :remember_created_at

      # Campos customizados
      t.string  :nome,          null: false
      t.string  :telefone
      t.string  :pin_code,      limit: 4   # apenas motoristas
      t.integer :role,          null: false, default: 3  # 0=admin,1=gerente,2=operador,3=motorista
      t.boolean :ativo,         null: false, default: true
      t.string  :tema_preferido, default: 'dark'  # dark | light

      t.timestamps
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    add_index :users, :pin_code
    add_index :users, :role
  end
end
