CREATE TABLE IF NOT EXISTS nodes (
    id                TEXT PRIMARY KEY,
    chain_id          TEXT NOT NULL REFERENCES chains(id) ON DELETE CASCADE,
    parent_id         TEXT REFERENCES nodes(id) ON DELETE CASCADE,
    audio_path        TEXT,
    duration_s        REAL,
    status            TEXT NOT NULL DEFAULT 'pending',
    is_committed      INTEGER NOT NULL DEFAULT 0,
    prompt            TEXT NOT NULL DEFAULT '',
    energy            REAL,
    tempo_feel        REAL,
    density           REAL,
    cfg_coef          REAL NOT NULL DEFAULT 3.0,
    prompt_duration_s REAL NOT NULL DEFAULT 10.0,
    error_msg         TEXT,
    created_at        REAL NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_nodes_chain_id ON nodes(chain_id);
CREATE INDEX IF NOT EXISTS idx_nodes_parent_id ON nodes(parent_id);
