Initial commit: runnable Ask a Plumber First server.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func migrateUserProfileColumns(db *sql.DB, dialect string) error {
|
||||
cols := []string{"avatar_url", "state"}
|
||||
for _, col := range cols {
|
||||
var stmt string
|
||||
switch dialect {
|
||||
case dialectPostgres:
|
||||
stmt = fmt.Sprintf(`ALTER TABLE users ADD COLUMN IF NOT EXISTS %s TEXT NOT NULL DEFAULT ''`, col)
|
||||
default:
|
||||
stmt = fmt.Sprintf(`ALTER TABLE users ADD COLUMN %s TEXT NOT NULL DEFAULT ''`, col)
|
||||
}
|
||||
if _, err := db.Exec(stmt); err != nil {
|
||||
// SQLite errors when the column already exists.
|
||||
if dialect == dialectSQLite && strings.Contains(strings.ToLower(err.Error()), "duplicate column") {
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("add column %s: %w", col, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user