dorfteich/apps/api/prisma/migrations/20260711220000_comments/migration.sql
Claude Fable 5 4549d6d13f
All checks were successful
CI / Lint, typecheck, test (push) Successful in 3m19s
CI / Build container images (push) Has been skipped
CD / Build and push images (push) Successful in 4m55s
CD / Deploy to Test (push) Successful in 9s
CD / Smoke tests against Test (push) Successful in 1m5s
CD / Promote to Int (push) Successful in 10s
CI / Auth e2e pack (push) Successful in 5m20s
CI / Import/export fidelity gate (push) Successful in 45s
Add threaded page comments: data model, API, and comment policy (#91)
New comments table (thread via parent_id to the root, optional document
anchor on roots, resolved_at/by; page purge cascades, trash hides) with a
CommentsService enforcing the permission model: reading follows page
read, writing follows the new pond setting commentPolicy (readers |
editors) — 404 hides unreadable pages, 403 marks a failed write policy.
Endpoints: threaded list per page with an open/resolved filter (resolved
threads arrive collapsed by default), create (root or reply — replies
attach to roots only and carry no anchor), edit own, delete own (roots
with replies are admin-only, cascade), resolve/unresolve on roots for
everyone who may comment. Bodies are Markdown rendered through the shared
sanitizing pipeline; smuggled markup arrives as escaped text (fixture
test). The UI lands with #92.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
2026-07-11 21:42:29 +02:00

27 lines
1.0 KiB
SQL

-- Threaded page comments (issue #91).
CREATE TABLE "comments" (
"id" TEXT NOT NULL,
"page_id" TEXT NOT NULL,
"parent_id" TEXT,
"author_id" TEXT,
"body" TEXT NOT NULL,
"anchor" TEXT,
"resolved_at" TIMESTAMP(3),
"resolved_by" TEXT,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"edited_at" TIMESTAMP(3),
CONSTRAINT "comments_pkey" PRIMARY KEY ("id")
);
CREATE INDEX "comments_page_id_created_at_idx" ON "comments"("page_id", "created_at");
CREATE INDEX "comments_parent_id_idx" ON "comments"("parent_id");
ALTER TABLE "comments" ADD CONSTRAINT "comments_page_id_fkey"
FOREIGN KEY ("page_id") REFERENCES "pages"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "comments" ADD CONSTRAINT "comments_parent_id_fkey"
FOREIGN KEY ("parent_id") REFERENCES "comments"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "comments" ADD CONSTRAINT "comments_author_id_fkey"
FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;