-- 新闻文章表建表 SQL
-- 使用方法: sqlite3 backend/stock_agent.db < schema_news.sql

CREATE TABLE IF NOT EXISTS news_articles (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title VARCHAR(500) NOT NULL,
    content TEXT,
    content_hash VARCHAR(64) NOT NULL,
    url VARCHAR(1000) NOT NULL UNIQUE,
    source VARCHAR(100) NOT NULL,
    author VARCHAR(200),
    category VARCHAR(50) NOT NULL,
    tags JSON,
    published_at DATETIME,
    crawled_at DATETIME NOT NULL,
    llm_analyzed BOOLEAN DEFAULT 0,
    market_impact VARCHAR(20),
    impact_type VARCHAR(50),
    relevant_symbols JSON,
    sentiment VARCHAR(20),
    summary TEXT,
    key_points JSON,
    trading_advice TEXT,
    priority REAL DEFAULT 0.0,
    priority_reason TEXT,
    notified BOOLEAN DEFAULT 0,
    notification_sent_at DATETIME,
    notification_channel VARCHAR(50),
    quality_score REAL,
    duplicate_of INTEGER,
    is_active BOOLEAN DEFAULT 1,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL
);

-- 创建索引
CREATE INDEX IF NOT EXISTS idx_news_articles_content_hash ON news_articles(content_hash);
CREATE INDEX IF NOT EXISTS idx_news_articles_category ON news_articles(category);
CREATE INDEX IF NOT EXISTS idx_news_articles_published_at ON news_articles(published_at);
CREATE INDEX IF NOT EXISTS idx_news_articles_crawled_at ON news_articles(crawled_at);
CREATE INDEX IF NOT EXISTS idx_news_articles_llm_analyzed ON news_articles(llm_analyzed);
CREATE INDEX IF NOT EXISTS idx_news_articles_priority ON news_articles(priority);
CREATE INDEX IF NOT EXISTS idx_news_articles_notified ON news_articles(notified);
CREATE INDEX IF NOT EXISTS idx_news_articles_is_active ON news_articles(is_active);
CREATE INDEX IF NOT EXISTS idx_news_articles_created_at ON news_articles(created_at);
