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

@ -41,6 +41,7 @@ export async function createWithCodeRetry<T>(
const STORY_AUTO_RE = /^ST-(\d+)$/
const PBI_AUTO_RE = /^PBI-(\d+)$/
const TASK_AUTO_RE = /^T-(\d+)$/
const SPRINT_AUTO_RE = /^SP-(\d+)$/
function nextSequential(existing: (string | null)[], pattern: RegExp): number {
let max = 0
@ -82,3 +83,12 @@ export async function generateNextTaskCode(productId: string): Promise<string> {
return `T-${next}`
}
export async function generateNextSprintCode(productId: string): Promise<string> {
const sprints = await prisma.sprint.findMany({
where: { product_id: productId },
select: { code: true },
})
const next = nextSequential(sprints.map((s) => s.code), SPRINT_AUTO_RE)
return `SP-${next}`
}