ST-1239: Atomische database-migratie — todos naar ideas + droppen todos-tabel (#132)
* feat(cleanup): verwijder Todo's navlink en todo-referenties uit marketing page [cmotto5ia000nx3178lq6xk8d]
- nav-bar.tsx: Todo's navLink verwijderd; Ideas-link blijft staan
- app/page.tsx: /todos quick-access link, feature-entry en /api/todos API-doc verwijderd
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(cleanup): verwijder app/(app)/todos/ en components/todos/ [cmottjvzo000cx3172472cu4g]
* test(cleanup): verwijder POST /api/todos import en describe-block uit security.test.ts [cmotto5jn000px317kjqlba89]
- Import 'POST as postTodo' uit verwijderde todos-route verwijderd
- describe('POST /api/todos') sectie (3 tests) verwijderd
- 73 testfiles / 561 tests groen
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(cleanup): verwijder __tests__/api/todos.test.ts en __tests__/actions/todos-promote-idea.test.ts [cmottjw1u000fx317igq27mh5]
* feat(cleanup): verwijder actions/todos.ts en app/api/todos/route.ts; verplaats updateRolesAction naar actions/settings.ts [cmottjvy9000ax3173sgfjcqs]
* feat(db): migratie todos→ideas, counters bijwerken, todos dropt [cmotto5fh000jx317r7c5srvb]
Nieuwe Prisma-migratie die in één transactie actieve todos omzet naar
DRAFT-ideas met unieke IDEA-NNN codes, idea_code_counter per user
bijwerkt, en de todos-tabel dropt.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(schema): verwijder Todo model en relaties uit prisma/schema.prisma [cmottjvwu0008x317fwwodg3i]
* feat(cleanup): vervang open_todos door open_ideas in /api/products/:id/claude-context
Laatste prisma.todo-referentie verwijderd. Endpoint geeft nu open_ideas terug
(ideeën van de gebruiker voor dit product die niet gearchiveerd zijn en nog
niet status PLANNED hebben). Docs bijgewerkt in docs/api.md en
docs/api/rest-contract.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c18d17108c
commit
ab8c3dca3f
6 changed files with 85 additions and 34 deletions
|
|
@ -29,14 +29,26 @@ export async function GET(
|
||||||
return Response.json({ error: 'Product niet gevonden' }, { status: 404 })
|
return Response.json({ error: 'Product niet gevonden' }, { status: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
const [activeSprint, openTodos] = await Promise.all([
|
const [activeSprint, openIdeas] = await Promise.all([
|
||||||
prisma.sprint.findFirst({
|
prisma.sprint.findFirst({
|
||||||
where: { product_id: id, status: 'ACTIVE' },
|
where: { product_id: id, status: 'ACTIVE' },
|
||||||
select: { id: true, sprint_goal: true, status: true },
|
select: { id: true, sprint_goal: true, status: true },
|
||||||
}),
|
}),
|
||||||
prisma.todo.findMany({
|
prisma.idea.findMany({
|
||||||
where: { user_id: auth.userId, product_id: id, done: false, archived: false },
|
where: {
|
||||||
select: { id: true, title: true, description: true, created_at: true },
|
user_id: auth.userId,
|
||||||
|
product_id: id,
|
||||||
|
archived: false,
|
||||||
|
status: { not: 'PLANNED' },
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
code: true,
|
||||||
|
title: true,
|
||||||
|
description: true,
|
||||||
|
status: true,
|
||||||
|
created_at: true,
|
||||||
|
},
|
||||||
orderBy: { created_at: 'asc' },
|
orderBy: { created_at: 'asc' },
|
||||||
take: 50,
|
take: 50,
|
||||||
}),
|
}),
|
||||||
|
|
@ -89,6 +101,6 @@ export async function GET(
|
||||||
product,
|
product,
|
||||||
active_sprint: activeSprint,
|
active_sprint: activeSprint,
|
||||||
next_story: nextStoryPayload,
|
next_story: nextStoryPayload,
|
||||||
open_todos: openTodos,
|
open_ideas: openIdeas,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ curl -H "Authorization: Bearer $TOKEN" https://scrum4me.app/api/products
|
||||||
|
|
||||||
### `GET /api/products/:id/claude-context`
|
### `GET /api/products/:id/claude-context`
|
||||||
|
|
||||||
Bundled context voor Claude Code: product, actieve sprint, volgende story (met tasks) en open todos van de tokengebruiker — in één call.
|
Bundled context voor Claude Code: product, actieve sprint, volgende story (met tasks) en open ideas van de tokengebruiker — in één call.
|
||||||
|
|
||||||
**Response (200):**
|
**Response (200):**
|
||||||
```json
|
```json
|
||||||
|
|
@ -111,13 +111,13 @@ Bundled context voor Claude Code: product, actieve sprint, volgende story (met t
|
||||||
"priority", "sort_order", "status" }
|
"priority", "sort_order", "status" }
|
||||||
]
|
]
|
||||||
} | null,
|
} | null,
|
||||||
"open_todos": [
|
"open_ideas": [
|
||||||
{ "id", "title", "description", "created_at" }
|
{ "id", "code", "title", "description", "status", "created_at" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`open_todos` is gelimiteerd op 50 items, gesorteerd op `created_at` asc. Demo-tokens kunnen dit endpoint lezen.
|
`open_ideas` bevat ideeën van de gebruiker voor dit product die niet gearchiveerd zijn en nog niet de status `PLANNED` hebben (= nog niet als PBI gepromoveerd). Gelimiteerd op 50 items, gesorteerd op `created_at` asc. Demo-tokens kunnen dit endpoint lezen.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -H "Authorization: Bearer $TOKEN" \
|
curl -H "Authorization: Bearer $TOKEN" \
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ curl -H "Authorization: Bearer $TOKEN" https://scrum4me.app/api/products
|
||||||
|
|
||||||
### `GET /api/products/:id/claude-context`
|
### `GET /api/products/:id/claude-context`
|
||||||
|
|
||||||
Bundled context voor Claude Code: product, actieve sprint, volgende story (met tasks) en open todos van de tokengebruiker — in één call.
|
Bundled context voor Claude Code: product, actieve sprint, volgende story (met tasks) en open ideas van de tokengebruiker — in één call.
|
||||||
|
|
||||||
**Response (200):**
|
**Response (200):**
|
||||||
```json
|
```json
|
||||||
|
|
@ -120,13 +120,13 @@ Bundled context voor Claude Code: product, actieve sprint, volgende story (met t
|
||||||
"priority", "sort_order", "status" }
|
"priority", "sort_order", "status" }
|
||||||
]
|
]
|
||||||
} | null,
|
} | null,
|
||||||
"open_todos": [
|
"open_ideas": [
|
||||||
{ "id", "title", "description", "created_at" }
|
{ "id", "code", "title", "description", "status", "created_at" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`open_todos` is gelimiteerd op 50 items, gesorteerd op `created_at` asc. Demo-tokens kunnen dit endpoint lezen.
|
`open_ideas` bevat ideeën van de gebruiker voor dit product die niet gearchiveerd zijn en nog niet de status `PLANNED` hebben (= nog niet als PBI gepromoveerd). Gelimiteerd op 50 items, gesorteerd op `created_at` asc. Demo-tokens kunnen dit endpoint lezen.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -H "Authorization: Bearer $TOKEN" \
|
curl -H "Authorization: Bearer $TOKEN" \
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 708 KiB After Width: | Height: | Size: 743 KiB |
|
|
@ -0,0 +1,59 @@
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
WITH active_todos AS (
|
||||||
|
SELECT t.id, t.user_id, t.product_id, t.title, t.description, t.created_at
|
||||||
|
FROM todos t
|
||||||
|
WHERE t.done = false
|
||||||
|
AND t.archived = false
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM ideas i
|
||||||
|
WHERE i.user_id = t.user_id
|
||||||
|
AND lower(trim(i.title)) = lower(trim(t.title))
|
||||||
|
)
|
||||||
|
),
|
||||||
|
user_base AS (
|
||||||
|
SELECT ut.user_id, u.idea_code_counter AS base_counter
|
||||||
|
FROM (SELECT DISTINCT user_id FROM active_todos) ut
|
||||||
|
JOIN users u ON u.id = ut.user_id
|
||||||
|
),
|
||||||
|
ranked AS (
|
||||||
|
SELECT
|
||||||
|
at.user_id, at.product_id, at.title, at.description, at.created_at,
|
||||||
|
ub.base_counter,
|
||||||
|
ROW_NUMBER() OVER (PARTITION BY at.user_id ORDER BY at.created_at, at.id) AS rn
|
||||||
|
FROM active_todos at
|
||||||
|
JOIN user_base ub ON ub.user_id = at.user_id
|
||||||
|
),
|
||||||
|
inserted AS (
|
||||||
|
INSERT INTO ideas (
|
||||||
|
id, user_id, product_id, code, title, description,
|
||||||
|
status, archived, created_at, updated_at
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
gen_random_uuid()::text,
|
||||||
|
user_id,
|
||||||
|
product_id,
|
||||||
|
'IDEA-' || lpad((base_counter + rn)::text, 3, '0'),
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
'DRAFT',
|
||||||
|
false,
|
||||||
|
created_at,
|
||||||
|
now()
|
||||||
|
FROM ranked
|
||||||
|
RETURNING user_id,
|
||||||
|
(regexp_replace(code, '^IDEA-0*', ''))::int AS used_counter
|
||||||
|
)
|
||||||
|
UPDATE users u
|
||||||
|
SET idea_code_counter = sub.max_counter
|
||||||
|
FROM (
|
||||||
|
SELECT user_id, MAX(used_counter) AS max_counter
|
||||||
|
FROM inserted
|
||||||
|
GROUP BY user_id
|
||||||
|
) sub
|
||||||
|
WHERE u.id = sub.user_id
|
||||||
|
AND sub.max_counter > u.idea_code_counter;
|
||||||
|
|
||||||
|
DROP TABLE todos;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|
@ -127,7 +127,6 @@ model User {
|
||||||
roles UserRole[]
|
roles UserRole[]
|
||||||
api_tokens ApiToken[]
|
api_tokens ApiToken[]
|
||||||
products Product[]
|
products Product[]
|
||||||
todos Todo[]
|
|
||||||
ideas Idea[]
|
ideas Idea[]
|
||||||
product_members ProductMember[]
|
product_members ProductMember[]
|
||||||
assigned_stories Story[] @relation("StoryAssignee")
|
assigned_stories Story[] @relation("StoryAssignee")
|
||||||
|
|
@ -183,7 +182,6 @@ model Product {
|
||||||
sprints Sprint[]
|
sprints Sprint[]
|
||||||
stories Story[]
|
stories Story[]
|
||||||
tasks Task[]
|
tasks Task[]
|
||||||
todos Todo[]
|
|
||||||
members ProductMember[]
|
members ProductMember[]
|
||||||
active_for_users User[] @relation("UserActiveProduct")
|
active_for_users User[] @relation("UserActiveProduct")
|
||||||
claude_questions ClaudeQuestion[]
|
claude_questions ClaudeQuestion[]
|
||||||
|
|
@ -403,24 +401,6 @@ model ProductMember {
|
||||||
@@map("product_members")
|
@@map("product_members")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Todo {
|
|
||||||
id String @id @default(cuid())
|
|
||||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
|
||||||
user_id String
|
|
||||||
product Product? @relation(fields: [product_id], references: [id], onDelete: SetNull)
|
|
||||||
product_id String?
|
|
||||||
title String
|
|
||||||
description String? @db.VarChar(2000)
|
|
||||||
done Boolean @default(false)
|
|
||||||
archived Boolean @default(false)
|
|
||||||
created_at DateTime @default(now())
|
|
||||||
updated_at DateTime @updatedAt
|
|
||||||
|
|
||||||
@@index([user_id, done, archived])
|
|
||||||
@@index([user_id, product_id])
|
|
||||||
@@map("todos")
|
|
||||||
}
|
|
||||||
|
|
||||||
model Idea {
|
model Idea {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue