# Consolidação passa a filtrar por VEÍCULO em vez de rota (route_id era um
# UUID pouco legível). Troca a coluna route_ids por vehicle_ids.
class SwapRouteIdsForVehicleIdsOnConsolidacoes < ActiveRecord::Migration[7.1]
  def up
    unless column_exists?(:consolidacoes, :vehicle_ids)
      add_column :consolidacoes, :vehicle_ids, :jsonb, default: []
      add_index  :consolidacoes, :vehicle_ids, using: :gin
    end
    remove_column :consolidacoes, :route_ids if column_exists?(:consolidacoes, :route_ids)
  end

  def down
    unless column_exists?(:consolidacoes, :route_ids)
      add_column :consolidacoes, :route_ids, :jsonb, default: []
      add_index  :consolidacoes, :route_ids, using: :gin
    end
    remove_column :consolidacoes, :vehicle_ids if column_exists?(:consolidacoes, :vehicle_ids)
  end
end
