Shell
/**
* SQLite Database Schema
*/
export const SCHEMA = `
-- Scanned threads
CREATE TABLE IF NOT EXISTS threads (
id TEXT PRIMARY KEY,
url TEXT UNIQUE NOT NULL,
subreddit TEXT NOT NULL,
title TEXT NOT NULL,
score INTEGER DEFAULT 0,
num_comments INTEGER DEFAULT 0,
upvote_ratio REAL DEFAULT 0,
goldmine_score REAL DEFAULT 0,
selftext TEXT,
author TEXT,
created_utc INTEGER,
scanned_at TEXT NOT NULL,
analyzed INTEGER DEFAULT 0
);
-- Market insights extracted from threads
CREATE TABLE IF NOT EXISTS insights (
id TEXT PRIMARY KEY,
thread_id TEXT NOT NULL,
type TEXT NOT NULL, -- 'pain_point', 'opportunity', 'competitor', 'buying_signal', 'quote'
content TEXT NOT NULL,
metadata TEXT, -- JSON for additional fields
confidence TEXT, -- 'high', 'medium', 'low'
created_at TEXT NOT NULL,
FOREIGN KEY (thread_id) REFERENCES threads(id)
);
-- Agent run history
CREATE TABLE IF NOT EXISTS agent_runs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
started_at TEXT NOT NULL,
completed_at TEXT,
status TEXT DEFAULT 'running', -- 'running', 'completed', 'failed'
threads_scanned INTEGER DEFAULT 0,
insights_found INTEGER DEFAULT 0,
cost_usd REAL DEFAULT 0,
error_message TEXT
);
-- Tracked subreddits and queries
CREATE TABLE IF NOT EXISTS tracked_sources (
id INTEGER PRIMARY KEY AUTOINCREMENT,
subreddit TEXT NOT NULL,
query TEXT,
enabled INTEGER DEFAULT 1,
last_scanned TEXT,
created_at TEXT NOT NULL,
UNIQUE(subreddit, query)
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS idx_threads_subreddit ON threads(subreddit);
CREATE INDEX IF NOT EXISTS idx_threads_goldmine ON threads(goldmine_score DESC);
CREATE INDEX IF NOT EXISTS idx_threads_analyzed ON threads(analyzed);
CREATE INDEX IF NOT EXISTS idx_insights_type ON insights(type);
CREATE INDEX IF NOT EXISTS idx_insights_thread ON insights(thread_id);
`;