[drizzleAdapter] Invalid 'default' generation #1243

Closed
opened 2026-03-13 08:29:48 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @hasdfa on GitHub (May 21, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

npx @better-auth/cli generate -y

Current vs. Expected behavior

Current

Generating a default value without backticks, e.g. .default(pending)

Expected

Generating a default value with backticks, e.g. .default('pending')

What version of Better Auth are you using?

1.2.8

Provide environment information

System:
    OS: macOS 15.1
  Binaries:
    Node: 20.18.2 - ~/.nvm/versions/node/v20.18.2/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.2/bin/npm
    pnpm: 9.15.2 - ~/.nvm/versions/node/v20.18.2/bin/pnpm

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

Package

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import Stripe from 'stripe';
import { stripe } from '@better-auth/stripe';
import { oneTap, multiSession, organization, jwt, openAPI } from 'better-auth/plugins';
import { drizzle } from 'drizzle-orm/node-postgres';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import * as authDbSchema from './auth-db-schema';

  const databaseClient = drizzle.mock({
    schema: {
      ...authDbSchema,
    },
  });

  const db = drizzleAdapter(databaseClient, {
    provider: 'pg',
  });


export const auth = betterAuth({
    secret: process.env.auth_secret,
    database: db,
    emailAndPassword: {
      enabled: true,
    },
    socialProviders: {
      google: {
        clientId: process.env.GOOGLE_CLIENT_ID as string,
        clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
      },
    },
    plugins: [
      stripe({
        stripeClient: <stripe client>,
        stripeWebhookSecret: process.env.strip_webhook_secret,
        subscription: {
          enabled: true,
          organization: {
            enabled: true,
          },
        }
      }),
      jwt(),
      oneTap(),
      multiSession(),
      organization(),
      userEndpointPlugin(),
});

Additional context

Generated db schema

import { pgTable, text, timestamp, boolean, integer } from 'drizzle-orm/pg-core';

export const user = pgTable('user', {
  id: text('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
  emailVerified: boolean('email_verified')
    .$defaultFn(() => false)
    .notNull(),
  image: text('image'),
  createdAt: timestamp('created_at')
    .$defaultFn(() => /* @__PURE__ */ new Date())
    .notNull(),
  updatedAt: timestamp('updated_at')
    .$defaultFn(() => /* @__PURE__ */ new Date())
    .notNull(),
  stripeCustomerId: text('stripe_customer_id'),
});

export const session = pgTable('session', {
  id: text('id').primaryKey(),
  expiresAt: timestamp('expires_at').notNull(),
  token: text('token').notNull().unique(),
  createdAt: timestamp('created_at').notNull(),
  updatedAt: timestamp('updated_at').notNull(),
  ipAddress: text('ip_address'),
  userAgent: text('user_agent'),
  userId: text('user_id')
    .notNull()
    .references(() => user.id, { onDelete: 'cascade' }),
  activeOrganizationId: text('active_organization_id'),
});

export const account = pgTable('account', {
  id: text('id').primaryKey(),
  accountId: text('account_id').notNull(),
  providerId: text('provider_id').notNull(),
  userId: text('user_id')
    .notNull()
    .references(() => user.id, { onDelete: 'cascade' }),
  accessToken: text('access_token'),
  refreshToken: text('refresh_token'),
  idToken: text('id_token'),
  accessTokenExpiresAt: timestamp('access_token_expires_at'),
  refreshTokenExpiresAt: timestamp('refresh_token_expires_at'),
  scope: text('scope'),
  password: text('password'),
  createdAt: timestamp('created_at').notNull(),
  updatedAt: timestamp('updated_at').notNull(),
});

export const verification = pgTable('verification', {
  id: text('id').primaryKey(),
  identifier: text('identifier').notNull(),
  value: text('value').notNull(),
  expiresAt: timestamp('expires_at').notNull(),
  createdAt: timestamp('created_at').$defaultFn(() => /* @__PURE__ */ new Date()),
  updatedAt: timestamp('updated_at').$defaultFn(() => /* @__PURE__ */ new Date()),
});

export const subscription = pgTable('subscription', {
  id: text('id').primaryKey(),
  plan: text('plan').notNull(),
  referenceId: text('reference_id').notNull(),
  stripeCustomerId: text('stripe_customer_id'),
  stripeSubscriptionId: text('stripe_subscription_id'),
  status: text('status').default(incomplete),                                      // <--- Invalid
  periodStart: timestamp('period_start'),
  periodEnd: timestamp('period_end'),
  cancelAtPeriodEnd: boolean('cancel_at_period_end'),
  seats: integer('seats'),
});

export const jwks = pgTable('jwks', {
  id: text('id').primaryKey(),
  publicKey: text('public_key').notNull(),
  privateKey: text('private_key').notNull(),
  createdAt: timestamp('created_at').notNull(),
});

export const organization = pgTable('organization', {
  id: text('id').primaryKey(),
  name: text('name').notNull(),
  slug: text('slug').unique(),
  logo: text('logo'),
  createdAt: timestamp('created_at').notNull(),
  metadata: text('metadata'),
});

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(),                                    // <--- Invalid
  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(),                            // <--- Invalid
  expiresAt: timestamp('expires_at').notNull(),
  inviterId: text('inviter_id')
    .notNull()
    .references(() => user.id, { onDelete: 'cascade' }),
});
Originally created by @hasdfa on GitHub (May 21, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```shell npx @better-auth/cli generate -y ``` ### Current vs. Expected behavior ## Current Generating a default value without backticks, e.g. `.default(pending)` ## Expected Generating a default value with backticks, e.g. `.default('pending')` ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash System: OS: macOS 15.1 Binaries: Node: 20.18.2 - ~/.nvm/versions/node/v20.18.2/bin/node npm: 10.8.2 - ~/.nvm/versions/node/v20.18.2/bin/npm pnpm: 9.15.2 - ~/.nvm/versions/node/v20.18.2/bin/pnpm ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import Stripe from 'stripe'; import { stripe } from '@better-auth/stripe'; import { oneTap, multiSession, organization, jwt, openAPI } from 'better-auth/plugins'; import { drizzle } from 'drizzle-orm/node-postgres'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import * as authDbSchema from './auth-db-schema'; const databaseClient = drizzle.mock({ schema: { ...authDbSchema, }, }); const db = drizzleAdapter(databaseClient, { provider: 'pg', }); export const auth = betterAuth({ secret: process.env.auth_secret, database: db, emailAndPassword: { enabled: true, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, plugins: [ stripe({ stripeClient: <stripe client>, stripeWebhookSecret: process.env.strip_webhook_secret, subscription: { enabled: true, organization: { enabled: true, }, } }), jwt(), oneTap(), multiSession(), organization(), userEndpointPlugin(), }); ``` ### Additional context Generated db schema ```ts import { pgTable, text, timestamp, boolean, integer } from 'drizzle-orm/pg-core'; export const user = pgTable('user', { id: text('id').primaryKey(), name: text('name').notNull(), email: text('email').notNull().unique(), emailVerified: boolean('email_verified') .$defaultFn(() => false) .notNull(), image: text('image'), createdAt: timestamp('created_at') .$defaultFn(() => /* @__PURE__ */ new Date()) .notNull(), updatedAt: timestamp('updated_at') .$defaultFn(() => /* @__PURE__ */ new Date()) .notNull(), stripeCustomerId: text('stripe_customer_id'), }); export const session = pgTable('session', { id: text('id').primaryKey(), expiresAt: timestamp('expires_at').notNull(), token: text('token').notNull().unique(), createdAt: timestamp('created_at').notNull(), updatedAt: timestamp('updated_at').notNull(), ipAddress: text('ip_address'), userAgent: text('user_agent'), userId: text('user_id') .notNull() .references(() => user.id, { onDelete: 'cascade' }), activeOrganizationId: text('active_organization_id'), }); export const account = pgTable('account', { id: text('id').primaryKey(), accountId: text('account_id').notNull(), providerId: text('provider_id').notNull(), userId: text('user_id') .notNull() .references(() => user.id, { onDelete: 'cascade' }), accessToken: text('access_token'), refreshToken: text('refresh_token'), idToken: text('id_token'), accessTokenExpiresAt: timestamp('access_token_expires_at'), refreshTokenExpiresAt: timestamp('refresh_token_expires_at'), scope: text('scope'), password: text('password'), createdAt: timestamp('created_at').notNull(), updatedAt: timestamp('updated_at').notNull(), }); export const verification = pgTable('verification', { id: text('id').primaryKey(), identifier: text('identifier').notNull(), value: text('value').notNull(), expiresAt: timestamp('expires_at').notNull(), createdAt: timestamp('created_at').$defaultFn(() => /* @__PURE__ */ new Date()), updatedAt: timestamp('updated_at').$defaultFn(() => /* @__PURE__ */ new Date()), }); export const subscription = pgTable('subscription', { id: text('id').primaryKey(), plan: text('plan').notNull(), referenceId: text('reference_id').notNull(), stripeCustomerId: text('stripe_customer_id'), stripeSubscriptionId: text('stripe_subscription_id'), status: text('status').default(incomplete), // <--- Invalid periodStart: timestamp('period_start'), periodEnd: timestamp('period_end'), cancelAtPeriodEnd: boolean('cancel_at_period_end'), seats: integer('seats'), }); export const jwks = pgTable('jwks', { id: text('id').primaryKey(), publicKey: text('public_key').notNull(), privateKey: text('private_key').notNull(), createdAt: timestamp('created_at').notNull(), }); export const organization = pgTable('organization', { id: text('id').primaryKey(), name: text('name').notNull(), slug: text('slug').unique(), logo: text('logo'), createdAt: timestamp('created_at').notNull(), metadata: text('metadata'), }); 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(), // <--- Invalid 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(), // <--- Invalid expiresAt: timestamp('expires_at').notNull(), inviterId: text('inviter_id') .notNull() .references(() => user.id, { onDelete: 'cascade' }), }); ```
Author
Owner

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

yeah this should work on the coming releases!

@Kinfe123 commented on GitHub (May 22, 2025): yeah this should work on the coming releases!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1243