Bug: Duplicate rateLimit tables generated due to schema inclusion in both getAuthTables and createSchema #2743

Closed
opened 2026-03-13 10:17:06 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @UdaraWanasinghe on GitHub (Jan 21, 2026).

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Enable rate limiting in config and set storage to 'database'.
  2. Run the CLI to generate or migrate the database schema.
  3. Observe that two tables, 'rateLimit' and 'ratelimit', are created as both getAuthTables and createSchema add their own version.

Current vs. Expected behavior

Current behavior: Two tables named 'rateLimit' and 'ratelimit' are created when rate limiting is enabled and database storage is selected.

Expected behavior: Only one rate limit table, with the name respecting the config's 'modelName' (default 'rateLimit'), should be generated.


Root Cause:

  • The schema generation includes the rate limit table in both getAuthTables and in createSchema (factory.ts, line 1298).
  • This causes both names to appear, leading to duplicate tables and confusion, especially for migrations and runtime.
  • Casing inconsistencies (capital "L" vs lowercase "l") compound the problem.

Solution suggestion:

  • Refactor schema handling for the rate limit table to ensure it is only defined in one place, use a normalized table/model name (respect config modelName, defaulting to rateLimit), and consistently reference it throughout CLI, migration, and runtime logic.

What version of Better Auth are you using?

1.4.15

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 ZEN SMP PREEMPT_DYNAMIC Fri, 14 Nov 2025 06:54:07 +0000",
    "release": "6.17.8-zen1-1-zen"
  },
  "node": {
    "version": "v25.2.0",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.3.5"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "1.4.15",
    "config": {
      rateLimit: {
        enabled: true,
        storage: "database"
      }
    }
  }
}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

rateLimit: { enabled: true, storage: "database" }

Additional context

The bug is reproducible locally. See discussion at:

  • packages/core/src/db/get-tables.ts (rateLimit table added to schema)
  • packages/core/src/db/adapter/factory.ts line 1298 (rateLimit table added again for schema creation).

Refactor and centralize rateLimit table handling to avoid duplication.

Originally created by @UdaraWanasinghe on GitHub (Jan 21, 2026). Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce 1. Enable rate limiting in config and set storage to 'database'. 2. Run the CLI to generate or migrate the database schema. 3. Observe that two tables, 'rateLimit' and 'ratelimit', are created as both getAuthTables and createSchema add their own version. ### Current vs. Expected behavior **Current behavior**: Two tables named 'rateLimit' and 'ratelimit' are created when rate limiting is enabled and database storage is selected. **Expected behavior**: Only one rate limit table, with the name respecting the config's 'modelName' (default 'rateLimit'), should be generated. --- **Root Cause:** - The schema generation includes the rate limit table in both getAuthTables and in createSchema (`factory.ts`, line 1298). - This causes both names to appear, leading to duplicate tables and confusion, especially for migrations and runtime. - Casing inconsistencies (capital "L" vs lowercase "l") compound the problem. **Solution suggestion:** - Refactor schema handling for the rate limit table to ensure it is only defined in one place, use a normalized table/model name (respect config `modelName`, defaulting to `rateLimit`), and consistently reference it throughout CLI, migration, and runtime logic. ### What version of Better Auth are you using? 1.4.15 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 ZEN SMP PREEMPT_DYNAMIC Fri, 14 Nov 2025 06:54:07 +0000", "release": "6.17.8-zen1-1-zen" }, "node": { "version": "v25.2.0", "env": "development" }, "packageManager": { "name": "bun", "version": "1.3.5" }, "frameworks": null, "databases": null, "betterAuth": { "version": "1.4.15", "config": { rateLimit: { enabled: true, storage: "database" } } } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript rateLimit: { enabled: true, storage: "database" } ``` ### Additional context The bug is reproducible locally. See discussion at: - `packages/core/src/db/get-tables.ts` (rateLimit table added to schema) - `packages/core/src/db/adapter/factory.ts` line 1298 (rateLimit table added again for schema creation). Refactor and centralize rateLimit table handling to avoid duplication.
GiteaMirror added the bug label 2026-03-13 10:17:06 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 21, 2026):

Yes, this issue is well-suited for GitHub as it involves a bug with duplicate rateLimit tables being generated due to schema inclusion in both getAuthTables and createSchema.

To address the bug you're encountering, the next steps would typically include:

  1. Refactoring schema handling for the rate limit table to ensure it is only defined in one place.
  2. Normalizing the table/model name to respect the configuration's modelName (default being rateLimit) to prevent casing inconsistencies.
  3. Ensure updates to both CLI and migration processes to handle table definitions appropriately.

This should help you avoid the issue where both rateLimit and ratelimit tables appear during migration.

If you encounter any further specifics regarding the implementation or if there are more issues, feel free to ask, and let's troubleshoot together! Would you like to share more details about your current setup or any other issues you're facing?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 21, 2026): Yes, this issue is well-suited for GitHub as it involves a bug with duplicate rateLimit tables being generated due to schema inclusion in both `getAuthTables` and `createSchema`. To address the bug you're encountering, the next steps would typically include: 1. **Refactoring** schema handling for the rate limit table to ensure it is only defined in one place. 2. **Normalizing the table/model name** to respect the configuration's `modelName` (default being `rateLimit`) to prevent casing inconsistencies. 3. Ensure updates to both CLI and migration processes to handle table definitions appropriately. This should help you avoid the issue where both `rateLimit` and `ratelimit` tables appear during migration. If you encounter any further specifics regarding the implementation or if there are more issues, feel free to ask, and let's troubleshoot together! Would you like to share more details about your current setup or any other issues you're facing? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@bytaesu commented on GitHub (Jan 22, 2026):

I'm checking this!

@bytaesu commented on GitHub (Jan 22, 2026): I'm checking this!
Author
Owner

@bytaesu commented on GitHub (Jan 22, 2026):

Hi @UdaraWanasinghe,

It looks like this needs a fix, but before that, one question:
which database adapter does this issue occur with? 🧐

@bytaesu commented on GitHub (Jan 22, 2026): Hi @UdaraWanasinghe, It looks like this needs a fix, but before that, one question: which database adapter does this issue occur with? 🧐
Author
Owner

@UdaraWanasinghe commented on GitHub (Jan 22, 2026):

I used Convex database adapter. https://github.com/get-convex/better-auth
But this occurs regardless of the database adapter.

@UdaraWanasinghe commented on GitHub (Jan 22, 2026): I used Convex database adapter. https://github.com/get-convex/better-auth But this occurs regardless of the database adapter.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2743