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:
@@ -1,5 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getRedis } from "@/lib/redis";
|
||||
import { prisma } from "@codeboard/database";
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
@@ -8,13 +9,34 @@ export async function GET(
|
||||
const { id } = await params;
|
||||
const redis = getRedis();
|
||||
|
||||
const result = await redis.get(`codeboard:result:${id}`);
|
||||
if (!result) {
|
||||
let result = await redis.get(`codeboard:result:${id}`);
|
||||
|
||||
if (result) {
|
||||
return NextResponse.json(JSON.parse(result));
|
||||
}
|
||||
|
||||
const generation = await prisma.generation.findFirst({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
if (!generation || !generation.result) {
|
||||
return NextResponse.json(
|
||||
{ error: "Documentation not found" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(JSON.parse(result));
|
||||
const docs = generation.result as any;
|
||||
docs.id = id;
|
||||
docs.repoUrl = generation.repoUrl;
|
||||
docs.repoName = generation.repoName;
|
||||
|
||||
await redis.set(
|
||||
`codeboard:result:${id}`,
|
||||
JSON.stringify(docs),
|
||||
"EX",
|
||||
86400
|
||||
);
|
||||
|
||||
return NextResponse.json(docs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user