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:
Janpeter Visser 2026-05-06 12:25:37 +02:00 committed by GitHub
parent c18d17108c
commit ab8c3dca3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 85 additions and 34 deletions

View file

@ -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;