refactor: revert migration error ignoring since tracker is now synced
This commit is contained in:
@@ -2,12 +2,10 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunMigrations(db *sql.DB) error {
|
func RunMigrations(db *sql.DB) error {
|
||||||
@@ -47,23 +45,9 @@ func RunMigrations(db *sql.DB) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split by statement and execute one by one
|
// Strict execution: if it fails, it halts.
|
||||||
statements := strings.Split(string(migrationSQL), ";")
|
if _, err := db.Exec(string(migrationSQL)); err != nil {
|
||||||
for _, stmt := range statements {
|
return err
|
||||||
stmt = strings.TrimSpace(stmt)
|
|
||||||
if stmt == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := db.Exec(stmt); err != nil {
|
|
||||||
errStr := err.Error()
|
|
||||||
// Safely ignore duplicate columns/tables caused by old manual sqlite3 runs
|
|
||||||
if strings.Contains(errStr, "duplicate column name") || strings.Contains(errStr, "already exists") {
|
|
||||||
log.Printf("warning: ignoring expected error in %s: %v", migrationFile, err)
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("failed to execute statement in %s: %v\nStatement: %s", migrationFile, err, stmt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark as applied
|
// Mark as applied
|
||||||
|
|||||||
Reference in New Issue
Block a user