drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

Update `pushSchema` to respect drizzle instance casing

Open matchai opened this issue 2 months ago • 2 comments

[!NOTE]
The changes are ±30 lines. The bulk of the PR is adding unit tests.

Changes

  • Expose casing as 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

matchai avatar Nov 07 '25 00:11 matchai

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.

mintydev789 avatar Nov 10 '25 19:11 mintydev789

This would indeed work as you've written your test setup, with the PR merged 👍

matchai avatar Nov 10 '25 21:11 matchai