mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Close database after migrating. Add reset errors (#215)
This commit is contained in:
@@ -2,6 +2,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -38,10 +39,20 @@ func Initialize(databasePath string) {
|
|||||||
DB = conn
|
DB = conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reset(databasePath string) {
|
func Reset(databasePath string) error {
|
||||||
_ = DB.Close()
|
err := DB.Close()
|
||||||
_ = os.Remove(databasePath)
|
|
||||||
|
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)
|
Initialize(databasePath)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate the database
|
// Migrate the database
|
||||||
@@ -71,6 +82,7 @@ func runMigrations(databasePath string) {
|
|||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerRegexpFunc() {
|
func registerRegexpFunc() {
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package manager
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/stashapp/stash/pkg/database"
|
"github.com/stashapp/stash/pkg/database"
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
"github.com/stashapp/stash/pkg/logger"
|
||||||
@@ -10,9 +14,6 @@ import (
|
|||||||
"github.com/stashapp/stash/pkg/manager/jsonschema"
|
"github.com/stashapp/stash/pkg/manager/jsonschema"
|
||||||
"github.com/stashapp/stash/pkg/models"
|
"github.com/stashapp/stash/pkg/models"
|
||||||
"github.com/stashapp/stash/pkg/utils"
|
"github.com/stashapp/stash/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImportTask struct {
|
type ImportTask struct {
|
||||||
@@ -34,7 +35,12 @@ func (t *ImportTask) Start(wg *sync.WaitGroup) {
|
|||||||
}
|
}
|
||||||
t.Scraped = scraped
|
t.Scraped = scraped
|
||||||
|
|
||||||
database.Reset(config.GetDatabasePath())
|
err := database.Reset(config.GetDatabasePath())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("Error resetting database: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user