-- function_sequences: secuencias A→B(→C) repetidas de calls del agente.
-- Issue 0087 parte B. Candidatas a promoverse a pipeline one-shot.
-- Aditivo. Idempotente. Aplicado via embed.FS al abrir operations.db.

CREATE TABLE IF NOT EXISTS function_sequences (
    seq_hash       TEXT PRIMARY KEY,
    function_ids   TEXT NOT NULL,           -- JSON array ["fn_a","fn_b"] o ["fn_a","fn_b","fn_c"]
    length         INTEGER NOT NULL,
    occurrences    INTEGER NOT NULL DEFAULT 0,
    sessions_count INTEGER NOT NULL DEFAULT 0,
    success_count  INTEGER NOT NULL DEFAULT 0,
    last_seen      INTEGER NOT NULL,
    first_seen     INTEGER NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_function_sequences_occurrences ON function_sequences(occurrences);
CREATE INDEX IF NOT EXISTS idx_function_sequences_last_seen   ON function_sequences(last_seen);
CREATE INDEX IF NOT EXISTS idx_function_sequences_length      ON function_sequences(length);
