class AddNetworkIntelligenceToEvents < ActiveRecord::Migration[8.1]
  def change
    # Add network intelligence columns for denormalization
    add_column :events, :country, :string
    add_column :events, :company, :string
    add_column :events, :asn, :integer
    add_column :events, :asn_org, :string
    add_column :events, :is_datacenter, :boolean, default: false, null: false
    add_column :events, :is_vpn, :boolean, default: false, null: false
    add_column :events, :is_proxy, :boolean, default: false, null: false
    add_column :events, :network_range_id, :bigint

    # Add indexes for commonly queried fields
    add_index :events, :country
    add_index :events, :company
    add_index :events, :asn
    add_index :events, :network_range_id
    add_index :events, [:is_datacenter, :is_vpn, :is_proxy], name: 'index_events_on_network_flags'

    # Backfill skipped - run manually after migration
    # See script/backfill_network_intelligence.rb or lib/tasks/events.rake
  end
end
