-- 305_eid_review_set_draft_table.sql — 302_eid_review_set_draft.sql 분리본 (single-statement). asyncpg 러너가 prepared statement 로 처리해 multi-statement 거부 → 1 stmt/파일. 내용 불변.

CREATE TABLE IF NOT EXISTS eid_review_set_draft (
    id                   BIGSERIAL   PRIMARY KEY,
    user_id              BIGINT      NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    study_topic_id       BIGINT      REFERENCES study_topics(id) ON DELETE CASCADE,  -- nullable = cross-topic 세트
    question_ids         JSONB       NOT NULL,   -- ordered list[int]
    reason               VARCHAR(40) NOT NULL,   -- chronic | relapse | coverage | overdue
    actor                VARCHAR(20) NOT NULL,   -- 스탬프 = 'eid'
    source_weakness_id   BIGINT      REFERENCES eid_study_weakness(id) ON DELETE SET NULL,
    source_generated_at  TIMESTAMPTZ NOT NULL,   -- 스탬프
    supersedes_id        BIGINT      REFERENCES eid_review_set_draft(id) ON DELETE SET NULL,
    created_at           TIMESTAMPTZ NOT NULL DEFAULT now()
);
