Clean up migrations code
This commit is contained in:
parent
bb103e8723
commit
2a70d6b723
1 changed files with 6 additions and 4 deletions
|
@ -2,6 +2,7 @@ package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ type migration func(*xorm.Engine) error
|
||||||
|
|
||||||
// The version table. Should have only one row with id==1
|
// The version table. Should have only one row with id==1
|
||||||
type Version struct {
|
type Version struct {
|
||||||
Id int64 `xorm:"pk"`
|
Id int64
|
||||||
Version int64
|
Version int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +26,10 @@ func Migrate(x *xorm.Engine) error {
|
||||||
has, err := x.Get(currentVersion)
|
has, err := x.Get(currentVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
} else if !has {
|
||||||
if !has {
|
if _, err = x.InsertOne(currentVersion); err != nil {
|
||||||
_, err = x.InsertOne(currentVersion)
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v := currentVersion.Version
|
v := currentVersion.Version
|
||||||
|
|
Reference in a new issue