Organization plugin causes CLI to generate bad Drizzle schema #1222

Closed
opened 2026-03-13 08:29:03 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @jackmalcom on GitHub (May 18, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure Better Auth to use the organization plugin and the Drizzle adapter
  2. Attempt to generate Drizzle schema, for Neon Postgres in my case
  • Generated using bunx @better-auth/cli@latest generate --output ./src/db/betterAuth.ts -y && biome format --write ./src/db/betterAuth.ts

Current vs. Expected behavior

The role field in member is set to text("role").default(member).notNull() instead of text("role").default("member").notNull(), and status in invitation is set to text("status").default(pending).notNull() instead of text("status").default("pending").notNull().

What version of Better Auth are you using?

1.2.7

Provide environment information

- OS: Arch Linux
- Package manager: Bun 1.2.12

Which area(s) are affected? (Select all that apply)

Backend, Types

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

This seems to be identical behavior reported by SixtenK in this thread on the Discord server: https://discord.com/channels/1288403910284935179/1372866625807847424

I haven't really used Zod, but it looks like the Drizzle adapter in the CLI isn't picking up role and status a strings when creating default values here. They're the only two fields that are defined as their own variables so maybe there's something weird there?

Originally created by @jackmalcom on GitHub (May 18, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure Better Auth to use the organization plugin and the Drizzle adapter 2. Attempt to generate Drizzle schema, for Neon Postgres in my case - Generated using `bunx @better-auth/cli@latest generate --output ./src/db/betterAuth.ts -y && biome format --write ./src/db/betterAuth.ts` ### Current vs. Expected behavior The `role` field in `member` is set to `text("role").default(member).notNull()` instead of `text("role").default("member").notNull()`, and `status` in `invitation` is set to `text("status").default(pending).notNull()` instead of `text("status").default("pending").notNull()`. ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - OS: Arch Linux - Package manager: Bun 1.2.12 ``` ### Which area(s) are affected? (Select all that apply) Backend, Types ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context This seems to be identical behavior reported by SixtenK in this thread on the Discord server: https://discord.com/channels/1288403910284935179/1372866625807847424 I haven't really used Zod, but it looks like the Drizzle adapter in the CLI isn't picking up `role` and `status` a strings when creating default values [here](https://github.com/better-auth/better-auth/blob/659f8391df0b4ac9a03f05a441a0497a71c52e73/packages/cli/src/generators/drizzle.ts#L139). They're the only two fields that are defined as their own variables so maybe there's something weird there?
Author
Owner

@Kinfe123 commented on GitHub (May 18, 2025):

can you please try installing the beta -pnpm i better-auth@beta

@Kinfe123 commented on GitHub (May 18, 2025): can you please try installing the beta -`pnpm i better-auth@beta`
Author
Owner

@jackmalcom commented on GitHub (May 18, 2025):

Can confirm the bug still exists when using better-auth@beta and bunx @better-auth/cli@beta generate

@jackmalcom commented on GitHub (May 18, 2025): Can confirm the bug still exists when using `better-auth@beta` and `bunx @better-auth/cli@beta generate`
Author
Owner

@totigm commented on GitHub (May 19, 2025):

Same here, using @better-auth/cli@1.2.7 doesn't have this issue, seems like v1.2.8 introduced it. Using the organization plugin is enough to reproduce this.

v1.2.7 doesn't generate a broken schema file, it just doesn't set a default at all for status or role

@totigm commented on GitHub (May 19, 2025): Same here, using `@better-auth/cli@1.2.7` doesn't have this issue, seems like v1.2.8 introduced it. Using the organization plugin is enough to reproduce this. v1.2.7 doesn't generate a broken schema file, it just doesn't set a default at all for `status` or `role`
Author
Owner

@totigm commented on GitHub (May 19, 2025):

This is in my node_modules when it maps over every field

if (attr.defaultValue) {
  if (typeof attr.defaultValue === "function") {
    type += `.$defaultFn(${attr.defaultValue})`;
  } else {
    type += `.default(${attr.defaultValue})`;
  }
}

but I cloned the repo and I see the following, which works great

if (attr.defaultValue) {
  if (typeof attr.defaultValue === "function") {
  	type += `.$defaultFn(${attr.defaultValue})`;
  } else if (typeof attr.defaultValue === "string") {
  	type += `.default("${attr.defaultValue}")`;
  } else {
  	type += `.default(${attr.defaultValue})`;
  }
}

it was probably fixed but not released to beta yet

UPDATE: yep, it's been fixed on commit e7aec18

@totigm commented on GitHub (May 19, 2025): This is in my node_modules when it maps over every field ```ts if (attr.defaultValue) { if (typeof attr.defaultValue === "function") { type += `.$defaultFn(${attr.defaultValue})`; } else { type += `.default(${attr.defaultValue})`; } } ``` but I cloned the repo and I see the following, which works great ```ts if (attr.defaultValue) { if (typeof attr.defaultValue === "function") { type += `.$defaultFn(${attr.defaultValue})`; } else if (typeof attr.defaultValue === "string") { type += `.default("${attr.defaultValue}")`; } else { type += `.default(${attr.defaultValue})`; } } ``` it was probably fixed but not released to beta yet UPDATE: yep, it's been fixed on commit [e7aec18](https://github.com/better-auth/better-auth/commit/e7aec18d7d297da2d0c8e3b85c348a459b6d0ae0)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1222