-- Migration 0041: model_operations.models
-- Missing prerequisite table: referenced via FK by 0036 (approval_proposals.model_id)
-- and 0038 (sell_decisions.model_id), and queried directly by OpenDartDailyBatchJob.cs
-- (SELECT DISTINCT ticker ... WHERE published_at <= @now), but never created by any
-- prior migration. Any fresh database fails at 0036 without this table.
--
-- Scope is intentionally minimal (only the columns actually referenced today). The full
-- Model Card / lifecycle schema (Freeze/Mature/Score/Diagnose/.../Manual Activation per
-- CLAUDE.md) is a separate, larger piece of work and is not guessed at here.

CREATE TABLE IF NOT EXISTS model_operations.models (
    id UUID PRIMARY KEY,
    ticker VARCHAR(20) NOT NULL,
    published_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    correlation_id UUID NOT NULL,
    revision INT NOT NULL DEFAULT 1
);

CREATE INDEX IF NOT EXISTS ix_models_ticker ON model_operations.models(ticker);
CREATE INDEX IF NOT EXISTS ix_models_published_at ON model_operations.models(published_at DESC);
