[PR #6547] [MERGED] fix(cli): deduplicate drizzle schema relationships #14983

Closed
opened 2026-04-13 09:45:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6547
Author: @ping-maxwell
Created: 12/5/2025
Status: Merged
Merged: 12/6/2025
Merged by: @Bekacru

Base: canaryHead: fix/drizzle-duplicated-relations


📝 Commits (4)

  • a3479fb fix(cli): deduplicate drizzle schema relationships
  • 11c08a3 fix(cli): correctly handle duplicate relations in drizzle schema generation
  • b9f0288 Merge branch 'canary' into fix/drizzle-duplicated-relations
  • 60b3fdc refactor(cli): improve relation handling in drizzle schema generation

📊 Changes

5 files changed (+540 additions, -40 deletions)

View changed files

📝 packages/cli/src/generators/drizzle.ts (+164 -36)
📝 packages/cli/test/__snapshots__/auth-schema-drizzle-use-plural.txt (+3 -3)
packages/cli/test/__snapshots__/auth-schema-duplicate-relations.txt (+130 -0)
packages/cli/test/__snapshots__/auth-schema-multi-relation.txt (+128 -0)
📝 packages/cli/test/generate.test.ts (+115 -1)

📄 Description

closes https://github.com/better-auth/better-auth/issues/6296, https://github.com/better-auth/better-auth/issues/6525

  • Implement logic to merge "one" relationships by key, combining their fields and references to prevent duplication.
  • Introduce a structure to track "many" relationships and avoid duplicates.
  • Add a test case to verify that duplicate relations are not generated in the drizzle schema output.

Summary by cubic

Deduplicates generated Drizzle relations, fixes export naming, and combines single “one” and “many” relations into one export. This avoids repeated blocks, naming collisions, and inconsistent relation keys.

  • Bug Fixes
    • Generate field-specific exports for duplicate “one” relations to prevent naming collisions.
    • Deduplicate “many” relations via a per-model key set; apply pluralization only to “many” relation keys.
    • Add snapshot tests for duplicate and multi-relation cases to verify no duplicates and correct export names.

Written for commit 60b3fdc2c2. Summary will update automatically 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/6547 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 12/5/2025 **Status:** ✅ Merged **Merged:** 12/6/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/drizzle-duplicated-relations` --- ### 📝 Commits (4) - [`a3479fb`](https://github.com/better-auth/better-auth/commit/a3479fb45c6f9a96fef99b05f8cd8776b9b8e0d6) fix(cli): deduplicate drizzle schema relationships - [`11c08a3`](https://github.com/better-auth/better-auth/commit/11c08a30eb7c2e3920e8e4d7c9a3300e8f6f0aba) fix(cli): correctly handle duplicate relations in drizzle schema generation - [`b9f0288`](https://github.com/better-auth/better-auth/commit/b9f028811452c11cbc4e0e4eb473af6e55fc323b) Merge branch 'canary' into fix/drizzle-duplicated-relations - [`60b3fdc`](https://github.com/better-auth/better-auth/commit/60b3fdc2c2ed5914f188ba95d857aa841b6f4301) refactor(cli): improve relation handling in drizzle schema generation ### 📊 Changes **5 files changed** (+540 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/src/generators/drizzle.ts` (+164 -36) 📝 `packages/cli/test/__snapshots__/auth-schema-drizzle-use-plural.txt` (+3 -3) ➕ `packages/cli/test/__snapshots__/auth-schema-duplicate-relations.txt` (+130 -0) ➕ `packages/cli/test/__snapshots__/auth-schema-multi-relation.txt` (+128 -0) 📝 `packages/cli/test/generate.test.ts` (+115 -1) </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/6296, https://github.com/better-auth/better-auth/issues/6525 - Implement logic to merge "one" relationships by key, combining their fields and references to prevent duplication. - Introduce a structure to track "many" relationships and avoid duplicates. - Add a test case to verify that duplicate relations are not generated in the drizzle schema output. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Deduplicates generated Drizzle relations, fixes export naming, and combines single “one” and “many” relations into one export. This avoids repeated blocks, naming collisions, and inconsistent relation keys. - **Bug Fixes** - Generate field-specific exports for duplicate “one” relations to prevent naming collisions. - Deduplicate “many” relations via a per-model key set; apply pluralization only to “many” relation keys. - Add snapshot tests for duplicate and multi-relation cases to verify no duplicates and correct export names. <sup>Written for commit 60b3fdc2c2ed5914f188ba95d857aa841b6f4301. Summary will update automatically 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:45: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#14983