From 3a6a4b6e9c4ce3789125714650ba611b1733a9ef Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Mon, 18 May 2026 09:26:26 -0400 Subject: [PATCH] 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 --- migrate.go | 3 +++ schema.sql | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/migrate.go b/migrate.go index 547dc58..e14af61 100644 --- a/migrate.go +++ b/migrate.go @@ -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) diff --git a/schema.sql b/schema.sql index 6f37680..f77ce16 100644 --- a/schema.sql +++ b/schema.sql @@ -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);