Organization schema does not have index on slug #2387

Closed
opened 2026-03-13 09:48:55 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @matteobadini on GitHub (Nov 25, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Add organization plugin
  2. Generate a db schema
  3. Organization table does not have index on slug

Current vs. Expected behavior

As per docs the organization table should have an index on the slug column.

Every other table created by the plugin have the recommended indexes

What version of Better Auth are you using?

1.4.1

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000",
    "release": "25.1.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.14 GB"
  },
  "node": {
    "version": "v22.21.1",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "9.15.4"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.3"
    },
    {
      "name": "react",
      "version": "19.2.0"
    },
    {
      "name": "hono",
      "version": "^4.10.6"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.0"
    },
    {
      "name": "drizzle",
      "version": "^0.44.7"
    },
    {
      "name": "@neondatabase/serverless",
      "version": "^1.0.2"
    }
  ],
  "betterAuth": {
    "version": "^1.4.1",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
  plugins: [
    organization()
  ]
});

Additional context

I'm willing to open a PR if needed

Originally created by @matteobadini on GitHub (Nov 25, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Add `organization` plugin 2. Generate a db schema 3. Organization table does not have index on `slug` ### Current vs. Expected behavior As per [docs](https://www.better-auth.com/docs/guides/optimizing-for-performance#recommended-fields-to-index) the organization table should have an index on the `slug` column. Every other table created by the plugin have the recommended indexes ### What version of Better Auth are you using? 1.4.1 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000", "release": "25.1.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.14 GB" }, "node": { "version": "v22.21.1", "env": "development" }, "packageManager": { "name": "pnpm", "version": "9.15.4" }, "frameworks": [ { "name": "next", "version": "16.0.3" }, { "name": "react", "version": "19.2.0" }, { "name": "hono", "version": "^4.10.6" } ], "databases": [ { "name": "pg", "version": "^8.16.0" }, { "name": "drizzle", "version": "^0.44.7" }, { "name": "@neondatabase/serverless", "version": "^1.0.2" } ], "betterAuth": { "version": "^1.4.1", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, plugins: [ organization() ] }); ``` ### Additional context I'm willing to open a PR if needed
GiteaMirror added the bug label 2026-03-13 09:48:55 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 25, 2025):

Thanks for reporting this. Based on your description, it appears that in version 1.4.1 the organization table schema is missing an index on the slug column—even though our documentation recommends having an index on that field to optimize performance. As a next step, you might consider opening a pull request to add the required index to the generated schema, ensuring that the migration script for the organization table includes the slug index. Have you noticed any performance bottlenecks related to this issue in your application? tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 25, 2025): Thanks for reporting this. Based on your description, it appears that in version 1.4.1 the organization table schema is missing an index on the slug column—even though our documentation recommends having an index on that field to optimize performance. As a next step, you might consider opening a pull request to add the required index to the generated schema, ensuring that the migration script for the organization table includes the slug index. Have you noticed any performance bottlenecks related to this issue in your application? tag @better-auth-agent if you would like an answer from the Agent <!-- 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

@vincentfretin commented on GitHub (Dec 3, 2025):

Don't you see CONSTRAINT "organization_slug_unique" UNIQUE("slug") in the migration file? I have it on better-auth 1.4.5 with postgres.
Although the cli doesn't report it as an index when running the migration, a unique constraint is an index.

@vincentfretin commented on GitHub (Dec 3, 2025): Don't you see `CONSTRAINT "organization_slug_unique" UNIQUE("slug")` in the migration file? I have it on better-auth 1.4.5 with postgres. Although the cli doesn't report it as an index when running the migration, a unique constraint is an index.
Author
Owner

@vincentfretin commented on GitHub (Dec 3, 2025):

Indexes reported by the adminer tool:
Image

@vincentfretin commented on GitHub (Dec 3, 2025): Indexes reported by the adminer tool: <img width="188" height="90" alt="Image" src="https://github.com/user-attachments/assets/95bd4294-7379-4dbe-ad88-0127f849bec1" />
Author
Owner

@ping-maxwell commented on GitHub (Dec 3, 2025):

Hey, yes just as @vincentfretin says, slug is indexed by unique indexes.

@ping-maxwell commented on GitHub (Dec 3, 2025): Hey, yes just as @vincentfretin says, `slug` is indexed by unique indexes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2387