-- Add origin_country column to profiles table
-- Stores ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB', 'CA')
-- Captured automatically at signup via ipinfo.io geolocation lookup

ALTER TABLE profiles
ADD COLUMN IF NOT EXISTS origin_country TEXT;

-- Add constraint for valid ISO 2-letter code format
ALTER TABLE profiles
ADD CONSTRAINT profiles_origin_country_format
CHECK (origin_country IS NULL OR origin_country ~ '^[A-Z]{2}$');

-- Add comment for documentation
COMMENT ON COLUMN profiles.origin_country IS 'ISO 3166-1 alpha-2 country code captured at signup via ipinfo.io geolocation';
