[PR #6913] feat: support drizzle relations v2 #32563

Open
opened 2026-04-17 23:21:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6913
Author: @ping-maxwell
Created: 12/20/2025
Status: 🔄 Open

Base: nextHead: feat/drizzle-relations-2


📝 Commits (10+)

  • dd7b8c9 feat: support drizzle relations v2
  • bc7a48c Update docs/content/docs/adapters/drizzle.mdx
  • a4da2e5 Merge branch 'canary' into feat/drizzle-relations-2
  • 240406a wip
  • 8f9744f Update pnpm-lock.yaml
  • fc5adb9 update: drizzle-orm
  • 6c39c2b fix: revert old drizzle schema
  • 3bfdc3f update: drizzle + mysql working
  • 058fc99 chore: remove logs
  • e078191 update: pg working

📊 Changes

25 files changed (+2173 additions, -54 deletions)

View changed files

📝 .cspell.jsonc (+3 -1)
📝 .github/workflows/e2e.yml (+18 -9)
📝 biome.json (+1 -0)
📝 docs/content/docs/adapters/drizzle.mdx (+53 -0)
📝 e2e/adapter/test/adapter-factory/auth-flow.ts (+26 -24)
📝 e2e/adapter/test/adapter-factory/basic.ts (+0 -1)
📝 e2e/adapter/test/drizzle-adapter/adapter.drizzle.sqlite.test.ts (+1 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/.gitignore (+2 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/adapter.drizzle.mysql.test.ts (+88 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/adapter.drizzle.pg.test.ts (+87 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/adapter.drizzle.sqlite.test.ts (+85 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/drizzle-cli-utils.ts (+44 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/generate-schema.ts (+102 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/package.json (+16 -0)
e2e/adapter/test/drizzle-v2-relations-adapter/vitest.config.ts (+3 -0)
📝 knip.jsonc (+17 -0)
📝 packages/better-auth/package.json (+3 -0)
📝 packages/cli/src/generators/index.ts (+12 -10)
📝 packages/drizzle-adapter/package.json (+7 -1)
packages/drizzle-adapter/src/relations-v2/drizzle-adapter.ts (+732 -0)

...and 5 more files

📄 Description

closes https://github.com/better-auth/better-auth/issues/6766, https://github.com/orgs/better-auth/projects/6/views/2?pane=issue&itemId=168869122&issue=better-auth%7Cbetter-auth%7C5931

Notes

This PR introduces a new package: drizzle-adapter as @better-auth/drizzle-adapter which will need to be published on npm.
This PR also introduces better-auth/adapters/test-adapter as an export to the better-auth adapter test utility and all of it's tests. The reason I didn't export those functions right under better-auth/adapter was to avoid issues related to those functions needing the vitest import which could be bundled into other code if exported purely under /adapter.


Summary by cubic

Adds first-class support for Drizzle Relations v2 via a new @better-auth/drizzle-adapter/relations-v2 adapter and updates the CLI to generate v2 schema and relations. Enables join queries using Drizzle’s v2 relations without changing your database.

  • New Features

    • New relations-v2 adapter for pg, mysql, and sqlite with optional transactions, camelCase, pluralization, and debug logs.
    • Adapter-powered schema generation (createSchema) that outputs both schema and defineRelations; the CLI now prefers the adapter’s generator when available and falls back to built-ins.
  • Migration

    • Install: npm install @better-auth/drizzle-adapter
    • Update: import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2" and set provider ("sqlite" | "pg" | "mysql").
    • Generate: npx @better-auth/cli generate
    • Drizzle init: pass both schema and relations from the generated file to drizzle()

Written for commit 627eccb7cf. 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/6913 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 12/20/2025 **Status:** 🔄 Open **Base:** `next` ← **Head:** `feat/drizzle-relations-2` --- ### 📝 Commits (10+) - [`dd7b8c9`](https://github.com/better-auth/better-auth/commit/dd7b8c98fb7bc7fd2d89d31bc36ebe3cf9e0b803) feat: support drizzle relations v2 - [`bc7a48c`](https://github.com/better-auth/better-auth/commit/bc7a48c3080fbc093d6c0865522d1ae4507d9ba3) Update docs/content/docs/adapters/drizzle.mdx - [`a4da2e5`](https://github.com/better-auth/better-auth/commit/a4da2e5146a997c8be258ee19ac259aa3e658bbd) Merge branch 'canary' into feat/drizzle-relations-2 - [`240406a`](https://github.com/better-auth/better-auth/commit/240406a1de249b68fcdc384859bc95964287ec7a) wip - [`8f9744f`](https://github.com/better-auth/better-auth/commit/8f9744f44812d5ed568fe6838882a3b0e6f0715c) Update pnpm-lock.yaml - [`fc5adb9`](https://github.com/better-auth/better-auth/commit/fc5adb92ca73a0be30d6817c7cc9b91dc852f797) update: drizzle-orm - [`6c39c2b`](https://github.com/better-auth/better-auth/commit/6c39c2b7883eb4612101290a39c39cf952c96e86) fix: revert old drizzle schema - [`3bfdc3f`](https://github.com/better-auth/better-auth/commit/3bfdc3fe984cc57dbc6a26a56df3945c2d6f4961) update: drizzle + mysql working - [`058fc99`](https://github.com/better-auth/better-auth/commit/058fc99e29291f3e747138e03be0a66c0d00d080) chore: remove logs - [`e078191`](https://github.com/better-auth/better-auth/commit/e0781915535109f859e71f817dacd5b06e7b51cf) update: pg working ### 📊 Changes **25 files changed** (+2173 additions, -54 deletions) <details> <summary>View changed files</summary> 📝 `.cspell.jsonc` (+3 -1) 📝 `.github/workflows/e2e.yml` (+18 -9) 📝 `biome.json` (+1 -0) 📝 `docs/content/docs/adapters/drizzle.mdx` (+53 -0) 📝 `e2e/adapter/test/adapter-factory/auth-flow.ts` (+26 -24) 📝 `e2e/adapter/test/adapter-factory/basic.ts` (+0 -1) 📝 `e2e/adapter/test/drizzle-adapter/adapter.drizzle.sqlite.test.ts` (+1 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/.gitignore` (+2 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/adapter.drizzle.mysql.test.ts` (+88 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/adapter.drizzle.pg.test.ts` (+87 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/adapter.drizzle.sqlite.test.ts` (+85 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/drizzle-cli-utils.ts` (+44 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/generate-schema.ts` (+102 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/package.json` (+16 -0) ➕ `e2e/adapter/test/drizzle-v2-relations-adapter/vitest.config.ts` (+3 -0) 📝 `knip.jsonc` (+17 -0) 📝 `packages/better-auth/package.json` (+3 -0) 📝 `packages/cli/src/generators/index.ts` (+12 -10) 📝 `packages/drizzle-adapter/package.json` (+7 -1) ➕ `packages/drizzle-adapter/src/relations-v2/drizzle-adapter.ts` (+732 -0) _...and 5 more files_ </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/6766, https://github.com/orgs/better-auth/projects/6/views/2?pane=issue&itemId=168869122&issue=better-auth%7Cbetter-auth%7C5931 ### Notes This PR introduces a new package: `drizzle-adapter` as `@better-auth/drizzle-adapter` which will need to be published on npm. This PR also introduces `better-auth/adapters/test-adapter` as an export to the better-auth adapter test utility and all of it's tests. The reason I didn't export those functions right under `better-auth/adapter` was to avoid issues related to those functions needing the `vitest` import which could be bundled into other code if exported purely under `/adapter`. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds first-class support for Drizzle Relations v2 via a new @better-auth/drizzle-adapter/relations-v2 adapter and updates the CLI to generate v2 schema and relations. Enables join queries using Drizzle’s v2 relations without changing your database. - New Features - New relations-v2 adapter for pg, mysql, and sqlite with optional transactions, camelCase, pluralization, and debug logs. - Adapter-powered schema generation (createSchema) that outputs both schema and defineRelations; the CLI now prefers the adapter’s generator when available and falls back to built-ins. - Migration - Install: npm install @better-auth/drizzle-adapter - Update: import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2" and set provider ("sqlite" | "pg" | "mysql"). - Generate: npx @better-auth/cli generate - Drizzle init: pass both schema and relations from the generated file to drizzle() <sup>Written for commit 627eccb7cfe89e4cd8172c5401513d4fb6a5efbb. 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-17 23:21:02 -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#32563