0974ab2b4c
Replace the error-string-matching migration runner with a proper schema_version table. Migrations are now numbered and recorded; only unapplied versions run. Fresh databases seed at baseline version (CREATE TABLE already includes all columns). CREATE TABLE statements updated to include regions (sites) and node_id (check_history) — previously only added via ALTER. DeleteAlert now nulls sites.alert_id before deleting, preventing dangling references that caused every incident to hit the error path instead of alerting.
43 lines
778 B
Go
43 lines
778 B
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"strconv"
|
|
)
|
|
|
|
type Migration struct {
|
|
Version int
|
|
SQL string
|
|
}
|
|
|
|
type Dialect interface {
|
|
DriverName() string
|
|
CreateTablesSQL() []string
|
|
Migrations() []Migration
|
|
BaselineVersion() int
|
|
BoolFalse() string
|
|
ResetSequenceOnEmpty(db *sql.DB, table string)
|
|
ImportWipe(tx *sql.Tx)
|
|
ImportResetSequences(tx *sql.Tx)
|
|
UpsertNodeSQL() string
|
|
UpsertAlertHealthSQL() string
|
|
}
|
|
|
|
func rewritePlaceholders(query string, dollarStyle bool) string {
|
|
if !dollarStyle {
|
|
return query
|
|
}
|
|
buf := make([]byte, 0, len(query)+32)
|
|
n := 0
|
|
for i := 0; i < len(query); i++ {
|
|
if query[i] == '?' {
|
|
n++
|
|
buf = append(buf, '$')
|
|
buf = append(buf, []byte(strconv.Itoa(n))...)
|
|
} else {
|
|
buf = append(buf, query[i])
|
|
}
|
|
}
|
|
return string(buf)
|
|
}
|