Fix schema init crash on existing DBs with old verification_codes table

Move auth-related indexes into migrations so they run after column
additions. Previously CREATE INDEX on verification_codes(identifier)
would fail because the old table still had the email column.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 09:26:26 -04:00
parent 997bc8c1c6
commit 3a6a4b6e9c
2 changed files with 3 additions and 2 deletions
+3
View File
@@ -15,6 +15,9 @@ func runMigrations(database *sql.DB) {
`ALTER TABLE users ADD COLUMN email TEXT UNIQUE`,
// Verification codes use a generic identifier column.
`ALTER TABLE verification_codes ADD COLUMN identifier TEXT NOT NULL DEFAULT ''`,
// Indexes for auth tables (created here so they run after column migrations).
`CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id)`,
`CREATE INDEX IF NOT EXISTS idx_verification_codes_identifier ON verification_codes(identifier)`,
}
for _, m := range migrations {
_, err := database.Exec(m)