-- Migration 002: Market News table
-- Written by n8n workflows, read by the dashboard.

CREATE TABLE IF NOT EXISTS market_news (
    id              SERIAL PRIMARY KEY,
    source          VARCHAR(200) NOT NULL DEFAULT '',
    title           TEXT NOT NULL,
    url             TEXT NOT NULL DEFAULT '',
    category        VARCHAR(100),
    published_at    TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_market_news_published
    ON market_news (published_at DESC);

CREATE INDEX IF NOT EXISTS idx_market_news_category
    ON market_news (category);

-- Record this migration
INSERT INTO schema_version (version, description)
VALUES (2, 'market_news table for n8n-sourced articles')
ON CONFLICT (version) DO NOTHING;
