mirror of
https://github.com/stashapp/stash.git
synced 2025-12-11 13:58:10 -06:00
Only close DB if not nil (#1749)
This commit is contained in:
parent
25182997f1
commit
f292238e7f
@ -21,7 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var DB *sqlx.DB
|
var DB *sqlx.DB
|
||||||
var WriteMu *sync.Mutex
|
var WriteMu sync.Mutex
|
||||||
var dbPath string
|
var dbPath string
|
||||||
var appSchemaVersion uint = 28
|
var appSchemaVersion uint = 28
|
||||||
var databaseSchemaVersion uint
|
var databaseSchemaVersion uint
|
||||||
@ -84,7 +84,6 @@ func Initialize(databasePath string) error {
|
|||||||
|
|
||||||
const disableForeignKeys = false
|
const disableForeignKeys = false
|
||||||
DB = open(databasePath, disableForeignKeys)
|
DB = open(databasePath, disableForeignKeys)
|
||||||
WriteMu = &sync.Mutex{}
|
|
||||||
|
|
||||||
if err := runCustomMigrations(); err != nil {
|
if err := runCustomMigrations(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -97,7 +96,15 @@ func Close() error {
|
|||||||
WriteMu.Lock()
|
WriteMu.Lock()
|
||||||
defer WriteMu.Unlock()
|
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 {
|
func open(databasePath string, disableForeignKeys bool) *sqlx.DB {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user