CREATE TABLE IF NOT EXISTS issues (
    id           TEXT PRIMARY KEY,
    title        TEXT NOT NULL,
    status       TEXT NOT NULL,
    type         TEXT,
    scope        TEXT,
    priority     TEXT,
    domain_json  TEXT NOT NULL DEFAULT '[]',
    tags_json    TEXT NOT NULL DEFAULT '[]',
    depends_json TEXT NOT NULL DEFAULT '[]',
    blocks_json  TEXT NOT NULL DEFAULT '[]',
    related_json TEXT NOT NULL DEFAULT '[]',
    flow_id      TEXT,
    body         TEXT NOT NULL DEFAULT '',
    file_path    TEXT NOT NULL,
    mtime_ns     INTEGER NOT NULL,
    created_at   TEXT,
    updated_at   TEXT,
    completed    INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX IF NOT EXISTS idx_issues_status   ON issues(status);
CREATE INDEX IF NOT EXISTS idx_issues_priority ON issues(priority);
CREATE INDEX IF NOT EXISTS idx_issues_scope    ON issues(scope);

CREATE TABLE IF NOT EXISTS flows (
    id        TEXT PRIMARY KEY,
    title     TEXT NOT NULL,
    status    TEXT,
    kind      TEXT,
    tags_json TEXT NOT NULL DEFAULT '[]',
    body      TEXT NOT NULL DEFAULT '',
    file_path TEXT NOT NULL,
    mtime_ns  INTEGER NOT NULL
);
