[PR #8538] [MERGED] fix(db): use CREATE INDEX for postgres migration #8047

Closed
opened 2026-03-13 13:58:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8538
Author: @himself65
Created: 3/10/2026
Status: Merged
Merged: 3/10/2026
Merged by: @himself65

Base: canaryHead: fix/issue-8536


📝 Commits (2)

  • b5b15bd fix(db): use CREATE INDEX instead of ALTER TABLE ADD INDEX for PostgreSQL migrations (fixes #8536)
  • 402d8c8 test(db): add SQLite-based regression test for CREATE INDEX fix (issue #8536)

📊 Changes

2 files changed (+85 additions, -7 deletions)

View changed files

📝 packages/better-auth/src/db/get-migration-schema.test.ts (+79 -1)
📝 packages/better-auth/src/db/get-migration.ts (+6 -6)

📄 Description

Fixes: https://github.com/better-auth/better-auth/issues/8536

When adding indexed fields to existing tables, the migration code was using
Kysely's alterTable(...).addIndex(...) which generates MySQL-specific
ALTER TABLE ... ADD INDEX syntax, invalid in PostgreSQL.

Replace with createIndex(...) (matching the approach already used when
creating new tables) to generate valid CREATE INDEX SQL for all databases.


🔄 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/8538 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/10/2026 **Status:** ✅ Merged **Merged:** 3/10/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/issue-8536` --- ### 📝 Commits (2) - [`b5b15bd`](https://github.com/better-auth/better-auth/commit/b5b15bd6c85055b065ec522dd7fecf6e5214c62f) fix(db): use CREATE INDEX instead of ALTER TABLE ADD INDEX for PostgreSQL migrations (fixes #8536) - [`402d8c8`](https://github.com/better-auth/better-auth/commit/402d8c8aedee525371e4cca81ec5a1ef0fc5c96f) test(db): add SQLite-based regression test for CREATE INDEX fix (issue #8536) ### 📊 Changes **2 files changed** (+85 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/get-migration-schema.test.ts` (+79 -1) 📝 `packages/better-auth/src/db/get-migration.ts` (+6 -6) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/8536 When adding indexed fields to existing tables, the migration code was using Kysely's `alterTable(...).addIndex(...)` which generates MySQL-specific `ALTER TABLE ... ADD INDEX` syntax, invalid in PostgreSQL. Replace with `createIndex(...)` (matching the approach already used when creating new tables) to generate valid `CREATE INDEX` SQL for all databases. --- <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-03-13 13:58:07 -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#8047