refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (4)

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
2026-08-01 14:15:36 +02:00
co-authored by Cursor
parent 580972c0a0
commit 9aa4f331bf
40 changed files with 1259 additions and 927 deletions
+13 -14
View File
@@ -6,9 +6,10 @@
// chars (matches the VARCHAR(255) column). Fails soft — never returns a 500 for
// DB issues, just a generic error envelope.
import { eq } from "drizzle-orm";
import { apiError, apiJson } from "@/lib/api";
import { bearerUserId } from "@/lib/api-auth";
import { prisma } from "@/lib/prisma";
import { db, WebsiteArticleComments, WebsiteArticles } from "@/lib/db";
export const dynamic = "force-dynamic";
@@ -31,24 +32,22 @@ export async function POST(
}
try {
const article = await prisma.websiteArticles.findUnique({
where: { slug },
select: { id: true },
});
const [article] = await db
.select({ id: WebsiteArticles.id })
.from(WebsiteArticles)
.where(eq(WebsiteArticles.slug, slug))
.limit(1);
if (!article) {
return apiError("Article not found", 404);
}
const now = new Date();
await prisma.websiteArticleComments.create({
data: {
articleId: article.id,
userId: uid,
comment,
createdAt: now,
updatedAt: now,
},
select: { id: true },
await db.insert(WebsiteArticleComments).values({
articleId: article.id,
userId: uid,
comment,
createdAt: now,
updatedAt: now,
});
return apiJson({ ok: true });
+16 -14
View File
@@ -1,5 +1,6 @@
import { eq } from "drizzle-orm";
import { apiJson } from "@/lib/api";
import { prisma } from "@/lib/prisma";
import { db, WebsiteArticles } from "@/lib/db";
export const dynamic = "force-dynamic";
@@ -14,19 +15,20 @@ export async function GET(
const { slug } = await params;
try {
const article = await prisma.websiteArticles.findUnique({
where: { slug },
select: {
id: true,
title: true,
slug: true,
shortStory: true,
fullStory: true,
image: true,
createdAt: true,
updatedAt: true,
},
});
const [article] = await db
.select({
id: WebsiteArticles.id,
title: WebsiteArticles.title,
slug: WebsiteArticles.slug,
shortStory: WebsiteArticles.shortStory,
fullStory: WebsiteArticles.fullStory,
image: WebsiteArticles.image,
createdAt: WebsiteArticles.createdAt,
updatedAt: WebsiteArticles.updatedAt,
})
.from(WebsiteArticles)
.where(eq(WebsiteArticles.slug, slug))
.limit(1);
if (!article) {
return apiJson({ error: "Article not found" }, { status: 404 });