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:
49
packages/database/prisma/migrations/0001_init/migration.sql
Normal file
49
packages/database/prisma/migrations/0001_init/migration.sql
Normal 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;
|
||||
3
packages/database/prisma/migrations/migration_lock.toml
Normal file
3
packages/database/prisma/migrations/migration_lock.toml
Normal 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"
|
||||
Reference in New Issue
Block a user