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:
@@ -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)
|
||||
|
||||
@@ -61,5 +61,3 @@ CREATE TABLE IF NOT EXISTS verification_codes (
|
||||
CREATE INDEX IF NOT EXISTS idx_slots_event ON slots(event_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_claims_slot ON claims(slot_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_rsvps_event ON rsvps(event_id);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user