Problem
When using a custom PostgreSQL schema (e.g., auth instead of public), the CLI generate command outputs Drizzle schema using pgTable():
export const user = pgTable("user", {...});
Instead of using Drizzle's pgSchema() for explicit schema qualification:
const authSchema = pgSchema("auth");
export const user = authSchema.table("user", {...});
Current Workaround
The docs recommend using search_path at connection time:
connectionString: "postgres://...?options=-c search_path=auth"
This works for runtime queries, but the generated Drizzle schema doesn't reflect the actual database structure. This causes confusion and potential issues with drizzle-kit migrations.
Expected Behavior
If Better Auth detects a custom search_path in the database connection (or via a CLI flag), the generate command should output:
import { pgSchema } from "drizzle-orm/pg-core";
const authSchema = pgSchema("auth");
export const user = authSchema.table("user", {...});
export const session = authSchema.table("session", {...});
// etc.
Proposed Solutions
- Auto-detect: If the CLI config has a real database connection, detect
search_path and generate accordingly
- CLI flag: Add
--pg-schema auth flag to explicitly specify the schema
- Config option: Add
schema: "auth" option to the Drizzle adapter config
Environment
- Better Auth version: 1.4.x
- Database: PostgreSQL
- ORM: Drizzle
Related Docs
The docs mention custom schema support, but it only applies to migrate (Kysely) and runtime queries, not the generate command output for Drizzle users.
Problem
When using a custom PostgreSQL schema (e.g.,
authinstead ofpublic), the CLIgeneratecommand outputs Drizzle schema usingpgTable():Instead of using Drizzle's
pgSchema()for explicit schema qualification:Current Workaround
The docs recommend using
search_pathat connection time:connectionString: "postgres://...?options=-c search_path=auth"This works for runtime queries, but the generated Drizzle schema doesn't reflect the actual database structure. This causes confusion and potential issues with
drizzle-kitmigrations.Expected Behavior
If Better Auth detects a custom
search_pathin the database connection (or via a CLI flag), thegeneratecommand should output:Proposed Solutions
search_pathand generate accordingly--pg-schema authflag to explicitly specify the schemaschema: "auth"option to the Drizzle adapter configEnvironment
Related Docs
The docs mention custom schema support, but it only applies to
migrate(Kysely) and runtime queries, not thegeneratecommand output for Drizzle users.