Fix migration handlers

This commit is contained in:
kolaente 2020-12-23 02:20:47 +01:00
parent c532543ec7
commit 39e11fcb2b
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 12 additions and 17 deletions

View File

@ -19,20 +19,10 @@ package migration
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"xorm.io/xorm"
)
var x *xorm.Engine
// InitDB sets up the database connection to use in this module
func InitDB() (err error) {
x, err = db.CreateDBEngine()
if err != nil {
log.Criticalf("Could not connect to db: %v", err.Error())
return
}
// Cache
if config.CacheEnabled.GetBool() && config.CacheType.GetString() == "redis" {
db.RegisterTableStructsForCache(GetTables())

View File

@ -72,7 +72,7 @@ func (mw *MigrationWeb) Migrate(c echo.Context) error {
return handler.HandleHTTPError(err, c)
}
err = migration.SetMigrationStatus(s, ms, user)
err = migration.SetMigrationStatus(ms, user)
if err != nil {
return handler.HandleHTTPError(err, c)
}
@ -89,7 +89,7 @@ func (mw *MigrationWeb) Status(c echo.Context) error {
return handler.HandleHTTPError(err, c)
}
status, err := migration.GetMigrationStatus(s, ms, user)
status, err := migration.GetMigrationStatus(ms, user)
if err != nil {
return handler.HandleHTTPError(err, c)
}

View File

@ -17,10 +17,9 @@
package migration
import (
"time"
"xorm.io/xorm"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"time"
)
// Status represents this migration status
@ -37,7 +36,10 @@ func (s *Status) TableName() string {
}
// SetMigrationStatus sets the migration status for a user
func SetMigrationStatus(s *xorm.Session, m Migrator, u *user.User) (err error) {
func SetMigrationStatus(m Migrator, u *user.User) (err error) {
s := db.NewSession()
defer s.Close()
status := &Status{
UserID: u.ID,
MigratorName: m.Name(),
@ -47,7 +49,10 @@ func SetMigrationStatus(s *xorm.Session, m Migrator, u *user.User) (err error) {
}
// GetMigrationStatus returns the migration status for a migration and a user
func GetMigrationStatus(s *xorm.Session, m Migrator, u *user.User) (status *Status, err error) {
func GetMigrationStatus(m Migrator, u *user.User) (status *Status, err error) {
s := db.NewSession()
defer s.Close()
status = &Status{}
_, err = s.
Where("user_id = ? and migrator_name = ?", u.ID, m.Name()).