class CreateConsolidacoes < ActiveRecord::Migration[7.1]
  def change
    create_table :consolidacoes do |t|
      t.string   :nome,           null: false
      t.date     :data_inicio,    null: false
      t.date     :data_fim,       null: false
      t.integer  :status,         null: false, default: 0  # 0=rascunho,1=finalizada,2=arquivada
      t.decimal  :valor_total,    precision: 10, scale: 2, default: 0
      t.integer  :created_by,     null: false   # user_id
      t.integer  :finalizado_por                # user_id
      t.datetime :finalizado_em
      t.datetime :deleted_at                    # soft delete

      t.timestamps
    end

    add_index :consolidacoes, :status
    add_index :consolidacoes, :data_inicio
    add_index :consolidacoes, :data_fim
    add_index :consolidacoes, :deleted_at
    add_index :consolidacoes, :created_by
  end
end
