-- Migration 004: Add geolocation and AS information to detections table
-- Date: 2025-11-22
-- Description: Adds country, city, organization, AS number/name, ISP fields

ALTER TABLE detections 
ADD COLUMN IF NOT EXISTS country TEXT,
ADD COLUMN IF NOT EXISTS country_code TEXT,
ADD COLUMN IF NOT EXISTS city TEXT,
ADD COLUMN IF NOT EXISTS organization TEXT,
ADD COLUMN IF NOT EXISTS as_number TEXT,
ADD COLUMN IF NOT EXISTS as_name TEXT,
ADD COLUMN IF NOT EXISTS isp TEXT;

-- Create index on country for fast filtering
CREATE INDEX IF NOT EXISTS country_idx ON detections(country);

-- Update schema_version
INSERT INTO schema_version (version, description) 
VALUES (4, 'Add geolocation and AS information to detections')
ON CONFLICT (id) DO UPDATE SET 
  version = 4,
  applied_at = NOW(),
  description = 'Add geolocation and AS information to detections';
