a0c4b28d1e
Auto-detect whether the user entered an email or phone number. Email sends via Resend, phone sends via Twilio SMS. Users table has nullable phone and email columns; verification_codes uses a generic identifier field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30 lines
850 B
Go
30 lines
850 B
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
func runMigrations(database *sql.DB) {
|
|
migrations := []string{
|
|
`ALTER TABLE events ADD COLUMN description TEXT DEFAULT ''`,
|
|
`ALTER TABLE events ADD COLUMN user_id INTEGER REFERENCES users(id)`,
|
|
// Users may have email, phone, or both. Add whichever column is missing.
|
|
`ALTER TABLE users ADD COLUMN phone TEXT UNIQUE`,
|
|
`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 ''`,
|
|
}
|
|
for _, m := range migrations {
|
|
_, err := database.Exec(m)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), "duplicate column name") ||
|
|
strings.Contains(err.Error(), "no such column") {
|
|
continue
|
|
}
|
|
log.Printf("migration warning: %v", err)
|
|
}
|
|
}
|
|
}
|