Antonio Mika
·
2026-10-25
1ALTER TABLE analytics_visits ADD COLUMN IF NOT EXISTS is_mobile boolean;
2
3-- Only the current and previous month are read from raw visits. Matches db.IsMobileUserAgent.
4UPDATE analytics_visits
5SET is_mobile = (
6 COALESCE(user_agent, '') ILIKE '%mobile%'
7 OR COALESCE(user_agent, '') ILIKE '%android%'
8 OR COALESCE(user_agent, '') ILIKE '%iphone%'
9 OR COALESCE(user_agent, '') ILIKE '%ipad%'
10 OR COALESCE(user_agent, '') ILIKE '%ipod%'
11 OR COALESCE(user_agent, '') ILIKE '%blackberry%'
12 OR COALESCE(user_agent, '') ILIKE '%windows phone%'
13)
14WHERE is_mobile IS NULL
15 AND created_at >= date_trunc('month', now() AT TIME ZONE 'UTC') - interval '1 month';