[PR #6029] [MERGED] chore: fix crash in getMigrations after the first migration run #14641

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6029
Author: @Shridhad
Created: 11/16/2025
Status: Merged
Merged: 11/17/2025
Merged by: @Bekacru

Base: canaryHead: fix/get-migrations


📝 Commits (5)

  • d11c98c fix: issue with fields to be added in migrations
  • d3ae53a chore: use custom schema pool for test
  • 15cf1b1 Update packages/better-auth/src/db/get-migration-schema.test.ts
  • 1a28ae9 chore: close schema pool
  • a4342f2 chore: remove admin import

📊 Changes

2 files changed (+91 additions, -13 deletions)

View changed files

📝 packages/better-auth/src/db/get-migration-schema.test.ts (+88 -9)
📝 packages/better-auth/src/db/get-migration.ts (+3 -4)

📄 Description

Issue:

Calling getMigrations(options) after the migration has run at lease once, throw following error:

Cannot access 'useNumberId' before initialization

Cause:

Generation of alterTable fails while adding fields to the table as part of migration.tobeAdded at get-migrations.ts

The useNumberId was defined after the alter table migrations were generated.


Summary by cubic

Fixes a crash in getMigrations that threw “Cannot access 'useNumberId' before initialization” after the first migration run. Ensures alter table migrations correctly add plugin fields on subsequent runs.

  • Bug Fixes
    • Initialize useNumberId before alterTable generation to prevent the runtime error.
    • Add a test to verify columns are added when enabling a plugin schema after the initial migration; streamline PG connection setup and close pools in tests.

Written for commit a4342f2e5e. 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/6029 **Author:** [@Shridhad](https://github.com/Shridhad) **Created:** 11/16/2025 **Status:** ✅ Merged **Merged:** 11/17/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/get-migrations` --- ### 📝 Commits (5) - [`d11c98c`](https://github.com/better-auth/better-auth/commit/d11c98c0d4164574eb5024ac71a2409660e96a94) fix: issue with fields to be added in migrations - [`d3ae53a`](https://github.com/better-auth/better-auth/commit/d3ae53a7d9692d3265eadf3b5fbb3a2728198685) chore: use custom schema pool for test - [`15cf1b1`](https://github.com/better-auth/better-auth/commit/15cf1b19a2cbf48580d0d78455911ee3a0ede798) Update packages/better-auth/src/db/get-migration-schema.test.ts - [`1a28ae9`](https://github.com/better-auth/better-auth/commit/1a28ae98b69dfd1187e51bb82c4c66d352229f2c) chore: close schema pool - [`a4342f2`](https://github.com/better-auth/better-auth/commit/a4342f2e5edf800e0c80822a8eb272acd93ed9c7) chore: remove admin import ### 📊 Changes **2 files changed** (+91 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/get-migration-schema.test.ts` (+88 -9) 📝 `packages/better-auth/src/db/get-migration.ts` (+3 -4) </details> ### 📄 Description ## Issue: Calling `getMigrations(options)` after the migration has run at lease once, throw following error: ```log Cannot access 'useNumberId' before initialization ``` ## Cause: Generation of `alterTable` fails while adding fields to the table as part of `migration.tobeAdded` at [get-migrations.ts](https://github.com/better-auth/better-auth/blob/b855a956fec47345478c50a5a1cca011af5014a8/packages/better-auth/src/db/get-migration.ts#L396) The `useNumberId` was defined after the `alter table` migrations were generated. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes a crash in getMigrations that threw “Cannot access 'useNumberId' before initialization” after the first migration run. Ensures alter table migrations correctly add plugin fields on subsequent runs. - **Bug Fixes** - Initialize useNumberId before alterTable generation to prevent the runtime error. - Add a test to verify columns are added when enabling a plugin schema after the initial migration; streamline PG connection setup and close pools in tests. <sup>Written for commit a4342f2e5edf800e0c80822a8eb272acd93ed9c7. 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:33:35 -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#14641