CREATE TABLE IF NOT EXISTS article_views (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
slug text NOT NULL,
viewed_at timestamptz DEFAULT now(),
read_seconds integer DEFAULT 0,
referrer text DEFAULT '',
device_type text DEFAULT 'unknown'
);
CREATE INDEX IF NOT EXISTS idx_av_slug ON article_views(slug);
CREATE INDEX IF NOT EXISTS idx_av_date ON article_views(viewed_at DESC);
ALTER TABLE article_views ENABLE ROW LEVEL SECURITY;
CREATE POLICY "allow_insert" ON article_views FOR INSERT WITH CHECK (true);
CREATE POLICY "allow_select" ON article_views FOR SELECT USING (true);