Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: drizzle-seed is not taking into account the casing configuration. #3961

Open
1 task done
mau27galvez opened this issue Jan 16, 2025 · 0 comments
Open
1 task done
Assignees
Labels
bug Something isn't working

Comments

@mau27galvez
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.38.3

What version of drizzle-kit are you using?

0.30.1

Other packages

[email protected]

Describe the Bug

What is the undesired behavior?

Drizzle-seed tries to insert data to the columns using the name defined in the drizzle schema, which may not reflect the actual name of the column due to the casing configuration of drizzle, resulting in an error.

What are the steps to reproduce it?

drizzle.config.ts

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/lib/db/schema.ts",
  dialect: "postgresql",
  dbCredentials: {
    url: process.env.DATABASE_URL ?? "",
  },
  casing: "snake_case",
  breakpoints: false,
});

schema.ts

import { pgTable, text, uuid } from "drizzle-orm/pg-core";

export const usersTable = pgTable("users", {
  id: uuid().primaryKey(),
  name: text().notNull(),
  email: text().notNull().unique(),
  passwordHash: text().notNull(),
});

seed.ts

import { drizzle } from "drizzle-orm/postgres-js";
import { seed } from "drizzle-seed";
import * as schema from "./schema";

async function main() {
  const db = drizzle(process.env.DATABASE_URL!);

  const passwordHash = "hash"

  await seed(db, {
    userTable: schema.usersTable,
  }).refine((f) => ({
    usersTable: {
      columns: {
        name: f.firstName(),
        email: "[email protected]",
        passwordHash: passwordHash,
      },
      count: 1,
    }
  }));
}

When the seed script is executed, it crash with this error:

$ bun src/lib/db/seed.ts
783 |     query.execute()
784 |   }
785 | 
786 |   function ErrorResponse(x) {
787 |     query && (query.cursorFn || query.describeFirst) && write(Sync)
788 |     const error = Errors.postgres(parseError(x))
                               ^
PostgresError: column "passwordHash" of relation "users" does not exist
 code: "42703"

If the column passwordHash is changed to password_hash in the drizzle schema, it works as intended.

What is the desired result?

Drizzle-seed should be aware of the casing configuration and behave accordingly.

@mau27galvez mau27galvez added the bug Something isn't working label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants