CREATE TABLE issues (
    id          BIGSERIAL PRIMARY KEY,
    type        VARCHAR(50)  NOT NULL,
    assignee    VARCHAR(255),
    epic        VARCHAR(255),
    name        VARCHAR(255) NOT NULL,
    due_date    DATE,
    description TEXT,
    estimated_time DOUBLE PRECISION,
    priority    VARCHAR(50)  NOT NULL,
    status      VARCHAR(50)  NOT NULL DEFAULT 'draft',
    progress    INTEGER      NOT NULL DEFAULT 0
);

-- No FK on depends_on_id: dangling refs allowed (frontend cleans up)
CREATE TABLE issue_depends_on (
    issue_id      BIGINT NOT NULL REFERENCES issues (id) ON DELETE CASCADE,
    depends_on_id BIGINT NOT NULL
);

CREATE TABLE comments (
    id         BIGSERIAL PRIMARY KEY,
    issue_id   BIGINT       NOT NULL REFERENCES issues (id) ON DELETE CASCADE,
    text       TEXT         NOT NULL,
    created_at TIMESTAMPTZ  NOT NULL,
    updated_at TIMESTAMPTZ
);
