mirror of https://github.com/stashapp/stash.git
Fix database / migrations to work on Windows
This commit is contained in:
parent
87eeed7e71
commit
66e871a2d5
|
@ -8,9 +8,12 @@ import (
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/stashapp/stash/internal/logger"
|
"github.com/stashapp/stash/internal/logger"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DB *sqlx.DB
|
var DB *sqlx.DB
|
||||||
|
var appSchemaVersion uint = 1
|
||||||
|
|
||||||
func Initialize(databasePath string) {
|
func Initialize(databasePath string) {
|
||||||
runMigrations(databasePath)
|
runMigrations(databasePath)
|
||||||
|
@ -40,18 +43,27 @@ func runMigrations(databasePath string) {
|
||||||
Box: migrationsBox,
|
Box: migrationsBox,
|
||||||
Migrations: source.NewMigrations(),
|
Migrations: source.NewMigrations(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Golang migrate has an issue where the \ isn't recognized as a valid on windows
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
databasePath = strings.Replace(databasePath, "\\", "/", -1)
|
||||||
|
}
|
||||||
s, _ := WithInstance(packrSource)
|
s, _ := WithInstance(packrSource)
|
||||||
m, err := migrate.NewWithSourceInstance(
|
m, err := migrate.NewWithSourceInstance(
|
||||||
"packr2",
|
"packr2",
|
||||||
s,
|
s,
|
||||||
fmt.Sprintf("sqlite3:%s", databasePath),
|
fmt.Sprintf("sqlite3://%s", "file:"+databasePath),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.Steps(1)
|
databaseSchemaVersion, _, _ := m.Version()
|
||||||
if err != nil {
|
stepNumber := appSchemaVersion - databaseSchemaVersion
|
||||||
//panic(err.Error()) // TODO
|
if stepNumber != 0 {
|
||||||
|
err = m.Steps(int(stepNumber))
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue