REFACTORED - migrate the data layer from Prisma to Drizzle (unify the stack)
- Add lib/db (Drizzle schema: 7 tables + 6 enums + relations, postgres.js client), drizzle.config.ts, lib/db/enums.ts (Prisma-compatible enum objects) - Rewrite all 14 app consumers + 4 admin components to Drizzle - Move the test DB layer to Drizzle + in-process PGlite; convert all 8 integration test files + factories (371 tests green) - Remove Prisma: deps, prisma/ schema+migrations, lib/prisma.ts, Dockerfile prisma generate; wire db:generate/migrate/push/studio to drizzle-kit; update Makefile - Preserve the old seed as scripts/legacy-prisma-seed.cjs (needs a Drizzle rewrite)
This commit is contained in:
@@ -9,7 +9,10 @@ import {
|
||||
getPublishedPortfolioProjectBySlug,
|
||||
getPublishedPortfolioProjects,
|
||||
} from "@/lib/portfolio";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
import { db } from "@/lib/db";
|
||||
import { category, mediaUsage, portfolioAsset, portfolioProject, portfolioSection } from "@/lib/db/schema";
|
||||
import {
|
||||
createAsset,
|
||||
createCategory,
|
||||
@@ -75,15 +78,13 @@ describe("admin projects", () => {
|
||||
it("attaches media bindings to a project fetched by id", async () => {
|
||||
const project = await createProject();
|
||||
const cover = await createMediaAsset();
|
||||
await prisma.mediaUsage.create({
|
||||
data: {
|
||||
await db.insert(mediaUsage).values({
|
||||
assetId: cover.id,
|
||||
usageType: "PORTFOLIO_COVER",
|
||||
entityType: "portfolio-project",
|
||||
entityId: project.id,
|
||||
fieldKey: "cover",
|
||||
},
|
||||
});
|
||||
});
|
||||
const detail = await getAdminPortfolioProjectById(project.id);
|
||||
expect(detail?.coverMediaAssetId).toBe(cover.id);
|
||||
});
|
||||
@@ -127,15 +128,15 @@ describe("referential integrity", () => {
|
||||
it("restricts deleting a category that still has projects", async () => {
|
||||
const cat = await createCategory();
|
||||
await createProject({ categoryId: cat.id });
|
||||
await expect(prisma.category.delete({ where: { id: cat.id } })).rejects.toThrow();
|
||||
await expect(db.delete(category).where(eq(category.id, cat.id))).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("cascades section and asset deletion when a project is removed", async () => {
|
||||
const project = await createProject();
|
||||
await createSection(project.id);
|
||||
await createAsset(project.id);
|
||||
await prisma.portfolioProject.delete({ where: { id: project.id } });
|
||||
expect(await prisma.portfolioSection.count()).toBe(0);
|
||||
expect(await prisma.portfolioAsset.count()).toBe(0);
|
||||
await db.delete(portfolioProject).where(eq(portfolioProject.id, project.id));
|
||||
expect(await db.$count(portfolioSection)).toBe(0);
|
||||
expect(await db.$count(portfolioAsset)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user