feat(codes): code NOT NULL voor PBI/Story + Task.code + product_id denorm

- Pbi.code en Story.code worden NOT NULL (tot dusver optional)
- Task krijgt code String + product_id String denorm + @@unique([product_id, code])
- Product krijgt back-relation tasks Task[]
- Migratie backfillt bestaande NULL-rijen via PL/pgSQL:
  PBI-N (per product), ST-N (3-digit padded met GREATEST om
  truncatie van LPAD bij 4-digit nummers te voorkomen),
  T-N voor alle tasks
- Codes zijn stabiele identifiers (Jira-stijl flat-per-product),
  zodat re-parenting de code niet muteert

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-05-04 08:36:19 +02:00
parent 4b0ab8e4b2
commit 611b621d75
3 changed files with 84 additions and 2 deletions

View file

@ -144,6 +144,7 @@ model Product {
pbis Pbi[]
sprints Sprint[]
stories Story[]
tasks Task[]
todos Todo[]
members ProductMember[]
active_for_users User[] @relation("UserActiveProduct")
@ -160,7 +161,7 @@ model Pbi {
id String @id @default(cuid())
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
product_id String
code String? @db.VarChar(30)
code String @db.VarChar(30)
title String
description String?
priority Int
@ -188,7 +189,7 @@ model Story {
sprint_id String?
assignee User? @relation("StoryAssignee", fields: [assignee_id], references: [id], onDelete: SetNull)
assignee_id String?
code String? @db.VarChar(30)
code String @db.VarChar(30)
title String
description String?
acceptance_criteria String?
@ -246,8 +247,11 @@ model Task {
id String @id @default(cuid())
story Story @relation(fields: [story_id], references: [id], onDelete: Cascade)
story_id String
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
product_id String
sprint Sprint? @relation(fields: [sprint_id], references: [id])
sprint_id String?
code String @db.VarChar(30)
title String
description String?
implementation_plan String?
@ -266,8 +270,10 @@ model Task {
claude_questions ClaudeQuestion[]
claude_jobs ClaudeJob[]
@@unique([product_id, code])
@@index([story_id, priority, sort_order])
@@index([sprint_id, status])
@@index([product_id])
@@map("tasks")
}