[PR #8539] refactor(test): use snapshot assertions for migration SQL output tests #24948

Open
opened 2026-04-15 22:38:55 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8539
Author: @himself65
Created: 3/10/2026
Status: 🔄 Open

Base: mainHead: refactor/migration-snapshot-tests


📝 Commits (1)

  • 721d9d9 refactor(test): use snapshot assertions for migration SQL output tests

📊 Changes

2 files changed (+12 additions, -17 deletions)

View changed files

packages/better-auth/src/db/__snapshots__/get-migration-schema.test.ts.snap (+7 -0)
📝 packages/better-auth/src/db/get-migration-schema.test.ts (+5 -17)

📄 Description

Summary

  • Use CREATE INDEX instead of MySQL-specific ALTER TABLE ... ADD INDEX when adding indexed columns to existing tables, fixing PostgreSQL compatibility
  • Refactor migration SQL output tests to use Vitest snapshot assertions instead of string matching

Changes

  • Switch added-column index generation from alterTable(...).addIndex(...) to createIndex(...).on(...).columns(...)
  • Handle unique indexes by emitting .unique() when the field is unique
  • Add PostgreSQL and SQLite regression tests for the CREATE INDEX fix
  • Replace toContain/regex assertions with toMatchSnapshot() for compiled migration SQL

Fixes #8536
Ported from better-auth/ai#57

Test plan

  • SQLite snapshot test passes locally
  • PostgreSQL tests pass in CI (require Docker)

🔄 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/8539 **Author:** [@himself65](https://github.com/himself65) **Created:** 3/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `refactor/migration-snapshot-tests` --- ### 📝 Commits (1) - [`721d9d9`](https://github.com/better-auth/better-auth/commit/721d9d9f696dcff0fd544e7214dbe4427b0b28b7) refactor(test): use snapshot assertions for migration SQL output tests ### 📊 Changes **2 files changed** (+12 additions, -17 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/db/__snapshots__/get-migration-schema.test.ts.snap` (+7 -0) 📝 `packages/better-auth/src/db/get-migration-schema.test.ts` (+5 -17) </details> ### 📄 Description ## Summary - Use `CREATE INDEX` instead of MySQL-specific `ALTER TABLE ... ADD INDEX` when adding indexed columns to existing tables, fixing PostgreSQL compatibility - Refactor migration SQL output tests to use Vitest snapshot assertions instead of string matching ## Changes - Switch added-column index generation from `alterTable(...).addIndex(...)` to `createIndex(...).on(...).columns(...)` - Handle unique indexes by emitting `.unique()` when the field is unique - Add PostgreSQL and SQLite regression tests for the CREATE INDEX fix - Replace `toContain`/regex assertions with `toMatchSnapshot()` for compiled migration SQL ## Related Issues Fixes #8536 Ported from better-auth/ai#57 ## Test plan - [x] SQLite snapshot test passes locally - [ ] PostgreSQL tests pass in CI (require Docker) --- <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-15 22:38:55 -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#24948