feat: add PostgreSQL persistence for permanent shareable links

- Add PostgreSQL service to docker-compose with health checks
- Add migrate service that runs prisma migrate deploy on startup
- Integrate Prisma client in worker: checks for existing generations
  (same repo+commit) before regenerating, writes to Postgres on completion
- Update /api/docs/[id] with Redis → PostgreSQL fallback + cache repopulation
- Update Dockerfile: prisma generate in build, copy Prisma engine to worker/web
- Add @codeboard/database dependency to web and worker packages
- Add initial SQL migration for Generation and User tables
- Change removeOnComplete to { age: 3600 } for job retention
This commit is contained in:
Vectry
2026-02-09 20:23:41 +00:00
parent a49f05e8df
commit 30bfd88075
11 changed files with 170 additions and 6 deletions

View File

@@ -0,0 +1,49 @@
-- CreateEnum
CREATE TYPE "Status" AS ENUM ('QUEUED', 'CLONING', 'PARSING', 'GENERATING', 'RENDERING', 'COMPLETED', 'FAILED');
-- CreateTable
CREATE TABLE "Generation" (
"id" TEXT NOT NULL,
"repoUrl" TEXT NOT NULL,
"repoName" TEXT NOT NULL,
"commitHash" TEXT NOT NULL,
"status" "Status" NOT NULL DEFAULT 'QUEUED',
"progress" INTEGER NOT NULL DEFAULT 0,
"result" JSONB,
"error" TEXT,
"costUsd" DOUBLE PRECISION,
"duration" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"userId" TEXT,
"viewCount" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "Generation_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
"githubId" TEXT NOT NULL,
"login" TEXT NOT NULL,
"email" TEXT,
"avatarUrl" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Generation_repoUrl_idx" ON "Generation"("repoUrl");
-- CreateIndex
CREATE INDEX "Generation_status_idx" ON "Generation"("status");
-- CreateIndex
CREATE UNIQUE INDEX "Generation_repoUrl_commitHash_key" ON "Generation"("repoUrl", "commitHash");
-- CreateIndex
CREATE UNIQUE INDEX "User_githubId_key" ON "User"("githubId");
-- AddForeignKey
ALTER TABLE "Generation" ADD CONSTRAINT "Generation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"