Drizzle generate creates default values as variables instead of strings

In the code below the default values for status in invitation and role for member ( member and pending) should be strings but are generated as variables.
export const member = pgTable("member", {
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull().references(()=> organization.id, { onDelete: 'cascade' }),
userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }),
role: text('role').default(member).notNull(),
createdAt: timestamp('created_at').notNull()
});

export const invitation = pgTable("invitation", {
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull().references(()=> organization.id, { onDelete: 'cascade' }),
email: text('email').notNull(),
role: text('role'),
status: text('status').default(pending).notNull(),
expiresAt: timestamp('expires_at').notNull(),
inviterId: text('inviter_id').notNull().references(()=> user.id, { onDelete: 'cascade' })
});
export const member = pgTable("member", {
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull().references(()=> organization.id, { onDelete: 'cascade' }),
userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }),
role: text('role').default(member).notNull(),
createdAt: timestamp('created_at').notNull()
});

export const invitation = pgTable("invitation", {
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull().references(()=> organization.id, { onDelete: 'cascade' }),
email: text('email').notNull(),
role: text('role'),
status: text('status').default(pending).notNull(),
expiresAt: timestamp('expires_at').notNull(),
inviterId: text('inviter_id').notNull().references(()=> user.id, { onDelete: 'cascade' })
});
This is based on this config:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { organization } from "better-auth/plugins";
import { eq } from "drizzle-orm";
import { createAccessControl } from "better-auth/plugins/access";

export const auth = betterAuth({
baseURL: process.env.API_URL,
database: drizzleAdapter(Database.db, {
provider: "pg",
schema: Database.schema,
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
autoSignIn: true,
},

advanced: {
useSecureCookies: true,
defaultCookieAttributes: {
httpOnly: true,
secure: true,
path: "/",
sameSite: "lax", // Use 'lax' for better compatibility
},
cookiePrefix: "autopilot",
},

trustedOrigins: [process.env.API_URL || ""].filter(Boolean),
plugins: [organization()],
});
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { organization } from "better-auth/plugins";
import { eq } from "drizzle-orm";
import { createAccessControl } from "better-auth/plugins/access";

export const auth = betterAuth({
baseURL: process.env.API_URL,
database: drizzleAdapter(Database.db, {
provider: "pg",
schema: Database.schema,
}),
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
autoSignIn: true,
},

advanced: {
useSecureCookies: true,
defaultCookieAttributes: {
httpOnly: true,
secure: true,
path: "/",
sameSite: "lax", // Use 'lax' for better compatibility
},
cookiePrefix: "autopilot",
},

trustedOrigins: [process.env.API_URL || ""].filter(Boolean),
plugins: [organization()],
});
2 Replies
dizee
dizee4mo ago
I'm running into the same issue, I'm assuming there's probably some issue in the way the organization schema interacts with the drizzle generator in the CLI. Seems more likely to be a bug in the CLI but I'm too lazy to pull it down and do much poking beyond that. Relevant files: - CLI: https://github.com/better-auth/better-auth/blob/659f8391df0b4ac9a03f05a441a0497a71c52e73/packages/cli/src/generators/drizzle.ts#L139 - Organization schema: https://github.com/better-auth/better-auth/blob/659f8391df0b4ac9a03f05a441a0497a71c52e73/packages/better-auth/src/plugins/organization/schema.ts I'll go file an issue on gh
dizee
dizee4mo ago
GitHub
Organization plugin causes CLI to generate bad Drizzle schema · Is...
Is this suited for github? Yes, this is suited for github To Reproduce Configure Better Auth to use the organization plugin and the Drizzle adapter Attempt to generate Drizzle schema, for Neon Post...

Did you find this page helpful?