set schema version better
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
16
models/db.go
16
models/db.go
@@ -232,7 +232,6 @@ func CreateTables() {
|
||||
// Check the database schema version
|
||||
version, _ := GetSchemaVersion()
|
||||
if version < 3 {
|
||||
|
||||
// Remove users RoleId column
|
||||
userRoleIdCheck, _ := CheckColumnExists("users", "RoleId")
|
||||
if userRoleIdCheck {
|
||||
@@ -417,9 +416,18 @@ func CreateTables() {
|
||||
}
|
||||
|
||||
// Set the schema version
|
||||
if _, err = db.Exec("UPDATE schema SET Version = 3"); err != nil {
|
||||
log.Printf("Error setting schema to version 3 : '%s'", err)
|
||||
os.Exit(1)
|
||||
rowCount, _ = CheckCount("schema")
|
||||
if rowCount > 0 {
|
||||
if _, err = db.Exec("UPDATE schema SET Version = 3;"); err != nil {
|
||||
log.Printf("Error setting schema to version 3 : '%s'", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
if _, err = db.Exec("INSERT INTO schema (Version) VALUES (3);"); err != nil {
|
||||
log.Printf("Error setting schema to version 3 : '%s'", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user