[PR #7169] feat(drizzle): generate drizzle schema with schema namespace #15365

Open
opened 2026-04-13 09:59:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7169
Author: @ping-maxwell
Created: 1/7/2026
Status: 🔄 Open

Base: mainHead: feat/drizzle-gen-schema-namespace


📝 Commits (10+)

  • d50147c feat(drizzle): generate drizzle schema with schema namespace
  • c0c6025 Update drizzle.mdx
  • 525c80a Update packages/cli/src/generators/drizzle.ts
  • 1a0b5db Merge branch 'canary' into feat/drizzle-gen-schema-namespace
  • 4df0e75 Merge branch 'canary' into feat/drizzle-gen-schema-namespace
  • f5ee197 chore: lint
  • 88f863e Merge branch 'canary' into feat/drizzle-gen-schema-namespace
  • 2bd692c Merge branch 'canary' into feat/drizzle-gen-schema-namespace
  • 698c328 Merge branch 'canary' into feat/drizzle-gen-schema-namespace
  • 7b06368 Merge branch 'canary' into feat/drizzle-gen-schema-namespace

📊 Changes

6 files changed (+369 additions, -2 deletions)

View changed files

📝 .cspell.jsonc (+2 -1)
📝 docs/content/docs/adapters/drizzle.mdx (+27 -0)
📝 packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts (+16 -0)
📝 packages/cli/src/generators/drizzle.ts (+41 -1)
packages/cli/test/__snapshots__/auth-schema-pg-with-schema-name.txt (+129 -0)
📝 packages/cli/test/generate.test.ts (+154 -0)

📄 Description

closes https://github.com/better-auth/better-auth/issues/6606

Docs

Custom Schema namespace

If you're using PostgreSQL and you want to generate the schema with a custom schema namespace,
you can pass the schemaName option to the Drizzle adapter.

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schemaName: "auth", // [!code highlight]
  }),
});

Then when using the Better Auth CLI, it will generate the schema that looks something like this:

npx @better-auth/cli@latest generate
export const authSchema = pgSchema("auth");

export const user = authSchema.table("user", {...});
export const session = authSchema.table("session", {...});

Summary by cubic

Add schemaName support to the Drizzle adapter so the CLI can generate PostgreSQL schemas under a custom namespace. MySQL and SQLite remain unchanged.

  • New Features

    • Added schemaName to DrizzleAdapterConfig.
    • CLI generator imports pgSchema only when schemaName is set, declares const Schema = pgSchema(""), and uses Schema.table(...) for PostgreSQL.
    • Converts schemaName to a safe identifier (handles hyphens, non-alphanumerics, leading numbers).
    • Updated docs and added tests/snapshots for pg with/without schemaName; sqlite/mysql ignore schemaName.
  • Migration

    • PostgreSQL: set schemaName in drizzleAdapter config and re-run the Better Auth CLI.
    • No action needed for MySQL or SQLite.

Written for commit 47c7b2eb8c. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7169 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 1/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/drizzle-gen-schema-namespace` --- ### 📝 Commits (10+) - [`d50147c`](https://github.com/better-auth/better-auth/commit/d50147c93605972d701832a7116bbac119e22161) feat(drizzle): generate drizzle schema with schema namespace - [`c0c6025`](https://github.com/better-auth/better-auth/commit/c0c60253eaf2cc39682cc867fe69c157f7f5214a) Update drizzle.mdx - [`525c80a`](https://github.com/better-auth/better-auth/commit/525c80abc6bc6d6357eeb91522169240a7c771e3) Update packages/cli/src/generators/drizzle.ts - [`1a0b5db`](https://github.com/better-auth/better-auth/commit/1a0b5db4efeafb7e270579fc81818df95d33c7aa) Merge branch 'canary' into feat/drizzle-gen-schema-namespace - [`4df0e75`](https://github.com/better-auth/better-auth/commit/4df0e751ae74a2083c5d6d55336e94fedc58ce63) Merge branch 'canary' into feat/drizzle-gen-schema-namespace - [`f5ee197`](https://github.com/better-auth/better-auth/commit/f5ee197cd7eb3e562e8faeeda86aaf7289f0d333) chore: lint - [`88f863e`](https://github.com/better-auth/better-auth/commit/88f863efbeccb5ca67122c9be0f4e1f845d39cc9) Merge branch 'canary' into feat/drizzle-gen-schema-namespace - [`2bd692c`](https://github.com/better-auth/better-auth/commit/2bd692c12b216a1a87ba056821e9e2f68019a66c) Merge branch 'canary' into feat/drizzle-gen-schema-namespace - [`698c328`](https://github.com/better-auth/better-auth/commit/698c328645946fa83de59937988b70dd0b4e93c4) Merge branch 'canary' into feat/drizzle-gen-schema-namespace - [`7b06368`](https://github.com/better-auth/better-auth/commit/7b063689260c9a038d2ddd7c6f649bbd43c9adca) Merge branch 'canary' into feat/drizzle-gen-schema-namespace ### 📊 Changes **6 files changed** (+369 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `.cspell.jsonc` (+2 -1) 📝 `docs/content/docs/adapters/drizzle.mdx` (+27 -0) 📝 `packages/better-auth/src/adapters/drizzle-adapter/drizzle-adapter.ts` (+16 -0) 📝 `packages/cli/src/generators/drizzle.ts` (+41 -1) ➕ `packages/cli/test/__snapshots__/auth-schema-pg-with-schema-name.txt` (+129 -0) 📝 `packages/cli/test/generate.test.ts` (+154 -0) </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/6606 ## Docs ## Custom Schema namespace If you're using PostgreSQL and you want to generate the schema with a custom schema namespace, you can pass the `schemaName` option to the Drizzle adapter. ```ts export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schemaName: "auth", // [!code highlight] }), }); ``` Then when using the Better Auth CLI, it will generate the schema that looks something like this: ```bash npx @better-auth/cli@latest generate ``` ```ts export const authSchema = pgSchema("auth"); export const user = authSchema.table("user", {...}); export const session = authSchema.table("session", {...}); ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add schemaName support to the Drizzle adapter so the CLI can generate PostgreSQL schemas under a custom namespace. MySQL and SQLite remain unchanged. - **New Features** - Added schemaName to DrizzleAdapterConfig. - CLI generator imports pgSchema only when schemaName is set, declares const <identifier>Schema = pgSchema("<name>"), and uses <identifier>Schema.table(...) for PostgreSQL. - Converts schemaName to a safe identifier (handles hyphens, non-alphanumerics, leading numbers). - Updated docs and added tests/snapshots for pg with/without schemaName; sqlite/mysql ignore schemaName. - **Migration** - PostgreSQL: set schemaName in drizzleAdapter config and re-run the Better Auth CLI. - No action needed for MySQL or SQLite. <sup>Written for commit 47c7b2eb8ce463cdbc01bd65ab3dff4968bed904. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 09:59:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15365