Close database after migrating. Add reset errors (#215)

This commit is contained in:
WithoutPants
2019-11-18 08:39:33 +11:00
committed by Leopere
parent 6a75d5551f
commit 6dcb270471
2 changed files with 25 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package database
import (
"database/sql"
"errors"
"fmt"
"os"
"regexp"
@@ -38,10 +39,20 @@ func Initialize(databasePath string) {
DB = conn
}
func Reset(databasePath string) {
_ = DB.Close()
_ = os.Remove(databasePath)
func Reset(databasePath string) error {
err := DB.Close()
if err != nil {
return errors.New("Error closing database: " + err.Error())
}
err = os.Remove(databasePath)
if err != nil {
return errors.New("Error removing database: " + err.Error())
}
Initialize(databasePath)
return nil
}
// Migrate the database
@@ -71,6 +82,7 @@ func runMigrations(databasePath string) {
panic(err.Error())
}
}
m.Close()
}
func registerRegexpFunc() {