[GH-ISSUE #8347] disableMigration not working on plugins schemas #19694

Open
opened 2026-04-15 18:59:23 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Cicolas on GitHub (Mar 3, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8347

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a custom BetterAuth plugin with disableMigration: true in its schema:
    export const testPlugin = () => ({
      id: 'test',
      schema: {
        test: {
          fields: { name: { type: 'string', required: true } },
          disableMigration: true,
        },
      },
    } satisfies BetterAuthPlugin);
    
  2. Add the plugin to your betterAuth() config: plugins: [testPlugin()]
  3. Run better-auth generate --config auth.ts --output auth.schema.ts
  4. Observe the generated output file

Current vs. Expected behavior

The test table is generated in the output schema file despite disableMigration: true being set on the plugin schema entry.

Expected: when disableMigration: true is
set, the schema generator should skip that model and not emit a table definition for it.

What version of Better Auth are you using?

1.5.2

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Debian 6.12.73-1 (2026-02-17)",
    "release": "6.12.73+deb13-amd64",
    "cpuCount": 8,
    "cpuModel": "11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz",
    "totalMemory": "19.27 GB",
    "freeMemory": "6.02 GB"
  },
  "node": {
    "version": "v20.10.0",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.3.9"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "mysql2",
      "version": "^3.15.3"
    },
    {
      "name": "drizzle",
      "version": "^0.45.1"
    }
  ],
  "betterAuth": {
    "version": "~1.5.2",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { testPlugin } from "./test-plugin";

export const auth = betterAuth({
  plugins: [testPlugin()],
});

Additional context

The flag disableMigration works correctly at runtime (better-auth does not try to run
migrations for the table), but the generate CLI command ignores it and still emits the
table definition in the output file. This means external/custom tables that opt out of
migration management still pollute the generated schema file.

Originally created by @Cicolas on GitHub (Mar 3, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8347 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a custom BetterAuth plugin with `disableMigration: true` in its schema: ```ts export const testPlugin = () => ({ id: 'test', schema: { test: { fields: { name: { type: 'string', required: true } }, disableMigration: true, }, }, } satisfies BetterAuthPlugin); 2. Add the plugin to your betterAuth() config: plugins: [testPlugin()] 3. Run better-auth generate --config auth.ts --output auth.schema.ts 4. Observe the generated output file ### Current vs. Expected behavior The `test` table is generated in the output schema file despite `disableMigration: true` being set on the plugin schema entry. **Expected:** when `disableMigration: true` is set, the schema generator should skip that model and not emit a table definition for it. ### What version of Better Auth are you using? 1.5.2 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Debian 6.12.73-1 (2026-02-17)", "release": "6.12.73+deb13-amd64", "cpuCount": 8, "cpuModel": "11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", "totalMemory": "19.27 GB", "freeMemory": "6.02 GB" }, "node": { "version": "v20.10.0", "env": "development" }, "packageManager": { "name": "bun", "version": "1.3.9" }, "frameworks": null, "databases": [ { "name": "mysql2", "version": "^3.15.3" }, { "name": "drizzle", "version": "^0.45.1" } ], "betterAuth": { "version": "~1.5.2", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { testPlugin } from "./test-plugin"; export const auth = betterAuth({ plugins: [testPlugin()], }); ``` ### Additional context The flag disableMigration works correctly at runtime (better-auth does not try to run migrations for the table), but the generate CLI command ignores it and still emits the table definition in the output file. This means external/custom tables that opt out of migration management still pollute the generated schema file.
GiteaMirror added the databasecorebug labels 2026-04-15 18:59:24 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 3, 2026):

Hi @Cicolas! I'm Dosu and I’m helping the better-auth team.

This is a confirmed bug. The disableMigration flag is defined in the type definitions but is lost during schema merging and never actually checked.

Root cause: In getAuthTables, when plugin schemas are merged, only fields and modelName are preserved—the disableMigration property is dropped:

acc[key] = {
  fields: { ...acc[key]?.fields, ...value.fields },
  modelName: value.modelName || key,
  // ❌ disableMigration is NOT copied here
};

This means the flag never reaches the generators (Drizzle, Prisma, etc.) or the migration code.

Note: There's also a naming inconsistency—plugin schemas use disableMigration (singular) while core schemas use disableMigrations (plural).

Your report that runtime migrations work correctly may also be affected by this—the flag is lost before reaching the migration generation code as well.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3993791548 --> @dosubot[bot] commented on GitHub (Mar 3, 2026): <!-- Greeting --> Hi @Cicolas! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a confirmed bug. The `disableMigration` flag is defined in the [type definitions](https://github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/core/src/db/plugin.ts) but is **lost during schema merging** and never actually checked. **Root cause**: In [`getAuthTables`](https://github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/core/src/db/get-tables.ts#L7-L26), when plugin schemas are merged, only `fields` and `modelName` are preserved—the `disableMigration` property is dropped: ```typescript acc[key] = { fields: { ...acc[key]?.fields, ...value.fields }, modelName: value.modelName || key, // ❌ disableMigration is NOT copied here }; ``` This means the flag never reaches the generators (Drizzle, Prisma, etc.) or the migration code. **Note**: There's also a naming inconsistency—plugin schemas use `disableMigration` (singular) while [core schemas use `disableMigrations`](https://github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/core/src/db/type.ts#L296-L299) (plural). Your report that runtime migrations work correctly may also be affected by this—the flag is lost before reaching the [migration generation code](https://github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/better-auth/src/db/get-migration.ts#L227-L278) as well. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/88ba0cf2-b49d-48b7-8d07-7afc38eb0f33?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20confirmed%20bug.%20The%20%60disableMigration%60%20flag%20is%20defined%20in%20the%20%5Btype%20definitions%5D%28https%3A//github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/core/src/db/plugin.ts%29%20but%20is%20%2A%2Alost%20during%20schema%20merging%2A%2A%20and%20never%20actually%20checked.%0A%0A%2A%2ARoot%20cause%2A%2A%3A%20In%20%5B%60getAuthTables%60%5D%28https%3A//github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/core/src/db/get-tables.ts%23L7-L26%29%2C%20when%20plugin%20schemas%20are%20merged%2C%20only%20%60fields%60%20and%20%60modelName%60%20are%20preserved%E2%80%94the%20%60disableMigration%60%20property%20is%20dropped%3A%0A%0A%60%60%60typescript%0Aacc%5Bkey%5D%20%3D%20%7B%0A%20%20fields%3A%20%7B%20...acc%5Bkey%5D%3F.fields%2C%20...value.fields%20%7D%2C%0A%20%20modelName%3A%20value.modelName%20%7C%7C%20key%2C%0A%20%20//%20%E2%9D%8C%20disableMigration%20is%20NOT%20copied%20here%0A%7D%3B%0A%60%60%60%0A%0AThis%20means%20the%20flag%20never%20reaches%20the%20generators%20%28Drizzle%2C%20Prisma%2C%20etc.%29%20or%20the%20migration%20code.%0A%0A%2A%2ANote%2A%2A%3A%20There%27s%20also%20a%20naming%20inconsistency%E2%80%94plugin%20schemas%20use%20%60disableMigration%60%20%28singular%29%20while%20%5Bcore%20schemas%20use%20%60disableMigrations%60%5D%28https%3A//github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/core/src/db/type.ts%23L296-L299%29%20%28plural%29.%0A%0AYour%20report%20that%20runtime%20migrations%20work%20correctly%20may%20also%20be%20affected%20by%20this%E2%80%94the%20flag%20is%20lost%20before%20reaching%20the%20%5Bmigration%20generation%20code%5D%28https%3A//github.com/better-auth/better-auth/blob/54c84939ff6498d90a7c1147b4ade0061ed6c08d/packages/better-auth/src/db/get-migration.ts%23L227-L278%29%20as%20well.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/8347)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19694