Add a DB setup check on boot
This commit is contained in:
parent
7a9d11d426
commit
cde0b4b42a
|
@ -180,3 +180,14 @@ func newConfigFile() error {
|
||||||
|
|
||||||
return ioutil.WriteFile("config.toml", b, 0644)
|
return ioutil.WriteFile("config.toml", b, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkSchema checks if the DB schema is installed.
|
||||||
|
func checkSchema(db *sqlx.DB) (bool, error) {
|
||||||
|
if _, err := db.Exec(`SELECT id FROM templates LIMIT 1`); err != nil {
|
||||||
|
if isTableNotExistErr(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
|
@ -113,6 +113,14 @@ func init() {
|
||||||
install(migList[len(migList)-1].version, db, fs, !ko.Bool("yes"))
|
install(migList[len(migList)-1].version, db, fs, !ko.Bool("yes"))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the DB schema is installed.
|
||||||
|
if ok, err := checkSchema(db); err != nil {
|
||||||
|
log.Fatalf("error checking schema in DB: %v", err)
|
||||||
|
} else if !ok {
|
||||||
|
lo.Fatal("the database does not appear to be setup. Run --install.")
|
||||||
|
}
|
||||||
|
|
||||||
if ko.Bool("upgrade") {
|
if ko.Bool("upgrade") {
|
||||||
upgrade(db, fs, !ko.Bool("yes"))
|
upgrade(db, fs, !ko.Bool("yes"))
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
Loading…
Reference in New Issue