Voegt twee enums (ProductDocFolder met 8 kern-folders + ProductDocLogType), een Product-uitbreiding (enabled_doc_folders array met alle 8 als default) en twee modellen toe (ProductDoc met @@unique(product_id, folder, slug) + ProductDocLog met denormalized actor_user_id en doc_id nullable + SetNull). Bestaande producten krijgen de 8-folder-default automatisch via de ALTER TABLE DEFAULT — geen backfill nodig (zie plan §A.4). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
2.6 KiB
SQL
64 lines
2.6 KiB
SQL
-- CreateEnum
|
|
CREATE TYPE "ProductDocFolder" AS ENUM ('ADR', 'ARCHITECTURE', 'PATTERNS', 'PLANS', 'RUNBOOKS', 'SPECS', 'MANUAL', 'API');
|
|
|
|
-- CreateEnum
|
|
CREATE TYPE "ProductDocLogType" AS ENUM ('CREATED', 'UPDATED', 'DELETED', 'FOLDER_ENABLED', 'FOLDER_DISABLED');
|
|
|
|
-- AlterTable
|
|
ALTER TABLE "products" ADD COLUMN "enabled_doc_folders" "ProductDocFolder"[] NOT NULL DEFAULT ARRAY['ADR', 'ARCHITECTURE', 'PATTERNS', 'PLANS', 'RUNBOOKS', 'SPECS', 'MANUAL', 'API']::"ProductDocFolder"[];
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "product_docs" (
|
|
"id" TEXT NOT NULL,
|
|
"product_id" TEXT NOT NULL,
|
|
"folder" "ProductDocFolder" NOT NULL,
|
|
"slug" VARCHAR(80) NOT NULL,
|
|
"title" VARCHAR(200) NOT NULL,
|
|
"content_md" TEXT NOT NULL,
|
|
"status" VARCHAR(20) NOT NULL,
|
|
"created_by" TEXT NOT NULL,
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
|
|
CONSTRAINT "product_docs_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateTable
|
|
CREATE TABLE "product_doc_logs" (
|
|
"id" TEXT NOT NULL,
|
|
"product_id" TEXT NOT NULL,
|
|
"doc_id" TEXT,
|
|
"actor_user_id" TEXT NOT NULL,
|
|
"type" "ProductDocLogType" NOT NULL,
|
|
"metadata" JSONB,
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "product_doc_logs_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "product_docs_product_id_folder_slug_key" ON "product_docs"("product_id", "folder", "slug");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "product_docs_product_id_folder_updated_at_idx" ON "product_docs"("product_id", "folder", "updated_at");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "product_docs_product_id_status_idx" ON "product_docs"("product_id", "status");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "product_doc_logs_product_id_created_at_idx" ON "product_doc_logs"("product_id", "created_at");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "product_doc_logs_doc_id_created_at_idx" ON "product_doc_logs"("doc_id", "created_at");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "product_doc_logs_actor_user_id_created_at_idx" ON "product_doc_logs"("actor_user_id", "created_at");
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "product_docs" ADD CONSTRAINT "product_docs_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "product_doc_logs" ADD CONSTRAINT "product_doc_logs_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "product_doc_logs" ADD CONSTRAINT "product_doc_logs_doc_id_fkey" FOREIGN KEY ("doc_id") REFERENCES "product_docs"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|