feat: support drizzle relations v2#6913
feat: support drizzle relations v2#6913ping-maxwell wants to merge 92 commits intobetter-auth:mainfrom
Conversation
|
@ping-maxwell is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
better-auth
@better-auth/cli
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
There was a problem hiding this comment.
5 issues found across 15 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="docs/content/docs/adapters/drizzle.mdx">
<violation number="1" location="docs/content/docs/adapters/drizzle.mdx:180">
P2: Inconsistent CLI command format. The rest of the documentation uses `@better-auth/cli@latest` to ensure users get the latest version. This is particularly important here since users need the latest CLI to generate the v2 relation schema format.</violation>
</file>
<file name="packages/drizzle-adapter/drizzle-adapter.ts">
<violation number="1" location="packages/drizzle-adapter/drizzle-adapter.ts:434">
P1: Missing null check for `db.query` before accessing `db.query[model]`. Unlike `findOne` which correctly checks `!db.query || !db.query[model]`, this will throw a TypeError if `db.query` is undefined.</violation>
</file>
<file name="packages/drizzle-adapter/test/adapter.drizzle.sqlite.test.ts">
<violation number="1" location="packages/drizzle-adapter/test/adapter.drizzle.sqlite.test.ts:73">
P2: The SQLite database connection is not closed in `onFinish`. Unlike the PostgreSQL and MySQL tests which properly close their connections (`cleanupDatabase(true)` and `mysqlDB.end()` respectively), this test leaves the connection open. Add `sqliteDB.close()` for consistency and proper resource cleanup.</violation>
</file>
<file name="packages/drizzle-adapter/test/generate-schema.ts">
<violation number="1" location="packages/drizzle-adapter/test/generate-schema.ts:31">
P2: Rule violated: **Enforce Consistent Naming Conventions**
Single-letter function name `i` and parameter `x` are not descriptive. The function performs dynamic imports with cache clearing, so consider renaming to something like `dynamicImport` or `importFresh`, and rename `x` to `modulePath`.</violation>
</file>
<file name="packages/drizzle-adapter/test/adapter.drizzle.mysql.test.ts">
<violation number="1" location="packages/drizzle-adapter/test/adapter.drizzle.mysql.test.ts:58">
P2: Rule violated: **Enforce Consistent Naming Conventions**
Variable `tables_result` uses snake_case instead of camelCase. For consistency with the rest of the file and standard JavaScript conventions, rename to `tablesResult`.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
1 issue found across 17 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/drizzle-adapter-new/package.json">
<violation number="1" location="packages/drizzle-adapter-new/package.json:11">
P3: Repository metadata points to the wrong folder, so npm will link to a non-existent path. Update the repository.directory to the actual package directory.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
@half2me I also just ran into this a few days ago. In my case I think this was when The fix for me was to add an override depending on your package manager, e.g. for npm {
// ...
"overrides": {
"@better-auth/drizzle-adapter": "https://pkg.pr.new/better-auth/better-auth/@better-auth/drizzle-adapter@6913"
}
}And update the import to append import { drizzleAdapter } from "@better-auth/drizzle-adapter/relations-v2";Now it should work with the experimental joins feature again. |
|
I didn't have to touch overrides, this part was the key for me: I used to just have Thanks! |
|
Any timeline on when this will be merged? Been a minute and this fixes a show-stopping bug on drizzle's beta |
it will be merged alongside Drizzle's major release. |
|
@ping-maxwell can we get #7169 also included in the preview package for this pr? Right now I either have to choose, custom schema vs relations v2 😓 |
|
@ping-maxwell do we need to update relations in and maybe export new |
|
yes. @adamkasper note that the |
closes #6766, #5931
Notes
This PR introduces a new package:
drizzle-adapteras@better-auth/drizzle-adapterwhich will need to be published on npm.This PR also introduces
better-auth/adapters/test-adapteras an export to the better-auth adapter test utility and all of it's tests. The reason I didn't export those functions right underbetter-auth/adapterwas to avoid issues related to those functions needing thevitestimport 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
Migration
Written for commit 627eccb. Summary will update on new commits.