drizzle-orm
drizzle-orm copied to clipboard
Update `pushSchema` to respect drizzle instance casing
[!NOTE]
The changes are ±30 lines. The bulk of the PR is adding unit tests.
Changes
- Expose
casingas a readonly property in Drizzle instances - Pass the newly exposed property as an argument when generating the schema snapshot
- Unit test casing support for DBs that support
pushSchema
Fixes #5015
Would this make the following test setup work? Or would it still be necessary to specify the casing a second time?
// Source: https://github.com/drizzle-team/drizzle-orm/discussions/4216
vi.mock("~/server/db/provider.ts", async () => {
// Use require to defeat dynamic require error
// (https://github.com/drizzle-team/drizzle-orm/issues/2853#issuecomment-2668459509)
const { createRequire } = await vi.importActual<typeof import("node:module")>("node:module");
const require = createRequire(import.meta.url);
const { pushSchema } = require("drizzle-kit/api") as typeof import("drizzle-kit/api");
const client = new PGlite();
// This uses some of the same options from drizzle.config.ts
const db = drizzle({ client, schema, relations, casing: "snake_case" });
// Apply schema to db
const { apply } = await pushSchema(schema, db as any);
await apply();
return { db };
});
I'm dealing with the same issue of the casing not being respected.
This would indeed work as you've written your test setup, with the PR merged 👍