feat(PBI-59): Sprint.code (SP-N sequentieel per product) (#153)

Voegt een verplicht code-veld toe aan Sprint, sequentieel per product
(consistent met PBI-N, ST-NNN, T-N).

- **Schema** — `Sprint.code String @db.VarChar(30)` + `@@unique([product_id, code])`
- **Migratie** — voegt kolom toe als nullable, backfillt bestaande sprints
  via `ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY created_at)`
  als `SP-N`, en zet daarna NOT NULL + UNIQUE.
- **Generator** — `generateNextSprintCode(productId)` in lib/code-server.ts
  volgt het patroon van story/pbi/task; createSprintAction gebruikt
  `createWithCodeRetry` voor race-bescherming.
- **Seed** — sprint-counter per product (`SP-1`, `SP-2`, ...).

Zichtbaar in:
- Sprint-header (`Product › Sprint actief · SP-3`)
- JobCard + JobDetailPane voor SPRINT_IMPLEMENTATION jobs
- Insights: VelocityChart x-axis (compacter dan goal-truncated),
  AlignmentTrend tooltip, SprintInfoStrip
- actions/jobs-page.ts: `sprintCode` is weer een echte code i.p.v. null

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-05-07 20:10:16 +02:00 committed by GitHub
parent 16f01283ef
commit a268df3680
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 97 additions and 29 deletions

View file

@ -0,0 +1,23 @@
-- PBI-59: Sprint.code (SP-1, SP-2, ...) sequentieel per product
--
-- 1. Voeg nullable kolom toe
-- 2. Backfill bestaande rijen via ROW_NUMBER() per product op created_at
-- 3. Maak NOT NULL en voeg unieke index toe op (product_id, code)
ALTER TABLE "sprints" ADD COLUMN "code" VARCHAR(30);
WITH numbered AS (
SELECT
id,
product_id,
ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY created_at, id) AS n
FROM "sprints"
)
UPDATE "sprints" s
SET code = 'SP-' || numbered.n
FROM numbered
WHERE s.id = numbered.id;
ALTER TABLE "sprints" ALTER COLUMN "code" SET NOT NULL;
CREATE UNIQUE INDEX "sprints_product_id_code_key" ON "sprints"("product_id", "code");

View file

@ -299,6 +299,7 @@ model Sprint {
id String @id @default(cuid())
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
product_id String
code String @db.VarChar(30)
sprint_goal String
status SprintStatus @default(ACTIVE)
start_date DateTime? @db.Date
@ -309,6 +310,7 @@ model Sprint {
tasks Task[]
sprint_runs SprintRun[]
@@unique([product_id, code])
@@index([product_id, status])
@@map("sprints")
}

View file

@ -124,6 +124,7 @@ async function main() {
console.log(`Loaded backlog: ${milestones.length} milestones, ${milestones.reduce((acc, m) => acc + m.stories.length, 0)} stories`)
let productTaskCounter = 0
let sprintCounter = 0
for (const ms of milestones) {
const pbi = await prisma.pbi.create({
data: {
@ -139,6 +140,7 @@ async function main() {
const sprint = await prisma.sprint.create({
data: {
product_id: product.id,
code: `SP-${++sprintCounter}`,
sprint_goal: `${ms.key}${ms.goal}`,
status: ms.sprint_status,
},