ALTER TABLE requirements DROP CONSTRAINT requirements_phase_check;
ALTER TABLE requirements ADD CONSTRAINT requirements_phase_check
  CHECK (phase IN ('planning','prototyping','auditing','implementing','reviewing','done'));

CREATE TABLE requirement_prototypes (
  id             UUID PRIMARY KEY,
  requirement_id UUID NOT NULL REFERENCES requirements(id) ON DELETE CASCADE,
  version        INT  NOT NULL,
  content        TEXT NOT NULL,
  note           TEXT NOT NULL DEFAULT '',
  created_by     UUID NOT NULL REFERENCES users(id) ON DELETE RESTRICT,
  created_at     TIMESTAMPTZ NOT NULL DEFAULT now(),
  UNIQUE (requirement_id, version)
);
CREATE INDEX idx_requirement_prototypes_req ON requirement_prototypes(requirement_id);
