From 11937d8a8df40590f3b878137b8aac7b1d63e5e3 Mon Sep 17 00:00:00 2001 From: Janpeter Visser <30029041+madhura68@users.noreply.github.com> Date: Wed, 6 May 2026 10:18:20 +0200 Subject: [PATCH] fix(db): restore todos table after out-of-band drop (#131) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit De DB-tabel `public.todos` was buiten de migratie-historie om gedropt, terwijl `prisma/schema.prisma` `model Todo` en migration_lock.toml geen removal-migratie kenden. Gevolg: drift tussen schema (Todo aanwezig) en DB (tabel weg) — runtime-fout op alle `prisma.todo.*`-calls in `actions/todos.ts`, `app/api/todos/route.ts`, `app/(app)/todos/page.tsx`, `app/api/products/[id]/claude-context/route.ts` en MCP-tool create_todo. Deze migratie zet de tabel exact terug zoals het schema 'm beschrijft — gegenereerd via: npx prisma migrate diff --from-config-datasource \ --to-schema prisma/schema.prisma --script CREATE TABLE todos + 2 indexes + 2 foreign keys naar users (CASCADE) en products (SET NULL). Eerdere data is niet hersteld (geen backup-stap); de tabel is leeg. Dat is acceptabel: Todo's waren lichtgewicht notities zonder kritische data en de removal-Idea staat nog gepland (zie #128 → re-plan met de Make-Plan-prompt-update uit #130). Tot dat moment werken de Todo-flows weer. Verified locally: prisma migrate status (up to date), lint, typecheck, tests 564/564, next build. Co-authored-by: Claude Opus 4.7 (1M context) --- .../migration.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 prisma/migrations/20260506101436_restore_todos_table/migration.sql diff --git a/prisma/migrations/20260506101436_restore_todos_table/migration.sql b/prisma/migrations/20260506101436_restore_todos_table/migration.sql new file mode 100644 index 0000000..693c8b6 --- /dev/null +++ b/prisma/migrations/20260506101436_restore_todos_table/migration.sql @@ -0,0 +1,33 @@ +-- Restore todos table after out-of-band drop. +-- DB-state lost the table while schema.prisma still defined `model Todo` and +-- migration history showed no removal. This migration brings DB back in sync +-- with the schema. Generated via: +-- npx prisma migrate diff --from-config-datasource \ +-- --to-schema prisma/schema.prisma --script + +-- CreateTable +CREATE TABLE "todos" ( + "id" TEXT NOT NULL, + "user_id" TEXT NOT NULL, + "product_id" TEXT, + "title" TEXT NOT NULL, + "description" VARCHAR(2000), + "done" BOOLEAN NOT NULL DEFAULT false, + "archived" BOOLEAN NOT NULL DEFAULT false, + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "todos_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "todos_user_id_done_archived_idx" ON "todos"("user_id", "done", "archived"); + +-- CreateIndex +CREATE INDEX "todos_user_id_product_id_idx" ON "todos"("user_id", "product_id"); + +-- AddForeignKey +ALTER TABLE "todos" ADD CONSTRAINT "todos_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "todos" ADD CONSTRAINT "todos_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE SET NULL ON UPDATE CASCADE;