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:
@@ -1,11 +1,14 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { db } from "@/lib/db";
|
||||
import { appConfig, category } from "@/lib/db/schema";
|
||||
|
||||
describe("integration harness smoke test", () => {
|
||||
it("connects to the migrated test database and performs CRUD", async () => {
|
||||
const created = await prisma.category.create({
|
||||
data: {
|
||||
const [created] = await db
|
||||
.insert(category)
|
||||
.values({
|
||||
slug: "smoke",
|
||||
nameAr: "a",
|
||||
nameEn: "b",
|
||||
@@ -13,28 +16,27 @@ describe("integration harness smoke test", () => {
|
||||
descriptionAr: "a",
|
||||
descriptionEn: "b",
|
||||
descriptionDe: "c",
|
||||
},
|
||||
});
|
||||
})
|
||||
.returning();
|
||||
|
||||
expect(created.id).toBeTruthy();
|
||||
expect(created.isActive).toBe(true);
|
||||
|
||||
const found = await prisma.category.findUnique({ where: { slug: "smoke" } });
|
||||
const found = await db.query.category.findFirst({ where: eq(category.slug, "smoke") });
|
||||
expect(found?.nameEn).toBe("b");
|
||||
});
|
||||
|
||||
it("resets the database between tests", async () => {
|
||||
const count = await prisma.category.count();
|
||||
const count = await db.$count(category);
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
|
||||
it("supports enums and appconfig upsert", async () => {
|
||||
await prisma.appConfig.upsert({
|
||||
where: { key: "k" },
|
||||
update: { value: "v2" },
|
||||
create: { key: "k", value: "v1" },
|
||||
});
|
||||
const row = await prisma.appConfig.findUnique({ where: { key: "k" } });
|
||||
await db
|
||||
.insert(appConfig)
|
||||
.values({ key: "k", value: "v1" })
|
||||
.onConflictDoUpdate({ target: appConfig.key, set: { value: "v2" } });
|
||||
const row = await db.query.appConfig.findFirst({ where: eq(appConfig.key, "k") });
|
||||
expect(row?.value).toBe("v1");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user