-- Phase 8: simulation runs.
-- ratio_snapshots.simulation_id and torrent_snapshots.simulation_id already
-- exist (Phase 0/1/3); production reads filter `simulation_id IS NULL`.

CREATE TABLE IF NOT EXISTS simulation_runs (
    id                    INTEGER PRIMARY KEY AUTOINCREMENT,
    name                  TEXT NOT NULL,
    annotation            TEXT,
    proposed_config_json  TEXT NOT NULL,
    window_start          INTEGER NOT NULL,
    window_end            INTEGER NOT NULL,
    started_at            INTEGER NOT NULL,
    completed_at          INTEGER,
    status                TEXT NOT NULL,        -- "pending" | "running" | "completed" | "failed"
    summary_json          TEXT,
    promoted_at           INTEGER
);
CREATE INDEX IF NOT EXISTS idx_simulation_runs_status ON simulation_runs(status);
CREATE INDEX IF NOT EXISTS idx_simulation_runs_started ON simulation_runs(started_at DESC);
