Only close DB if not nil (#1749)

This commit is contained in:
WithoutPants 2021-09-21 21:57:50 +10:00 committed by GitHub
parent 25182997f1
commit f292238e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -21,7 +21,7 @@ import (
)
var DB *sqlx.DB
var WriteMu *sync.Mutex
var WriteMu sync.Mutex
var dbPath string
var appSchemaVersion uint = 28
var databaseSchemaVersion uint
@ -84,7 +84,6 @@ func Initialize(databasePath string) error {
const disableForeignKeys = false
DB = open(databasePath, disableForeignKeys)
WriteMu = &sync.Mutex{}
if err := runCustomMigrations(); err != nil {
return err
@ -97,7 +96,15 @@ func Close() error {
WriteMu.Lock()
defer WriteMu.Unlock()
return DB.Close()
if DB != nil {
if err := DB.Close(); err != nil {
return err
}
DB = nil
}
return nil
}
func open(databasePath string, disableForeignKeys bool) *sqlx.DB {