class SetDefaultForCounterCacheInventory < ActiveRecord::Migration
  def change
    reversible do |dir|
      dir.up do
        # Backfill existing NULL values to 0
        LocationNetwork.where(router_inventories_count: nil).update_all(router_inventories_count: 0)
      end
    end
    # Ensure the column is not nullable and has a default value
    change_column_default :location_networks, :router_inventories_count, 0
    change_column_null :location_networks, :router_inventories_count, false
  end
end
