}
// This is a sequence of migrations. Add new migrations to the bottom of the list.
-// If you want to "retire" a migration, remove it from the top of the list and
-// update _MIN_VER_DB accordingly
+// If you want to "retire" a migration, remove it from the top of the list and
+// update _MIN_VER_DB accordingly
var migrations = []Migration{
NewMigration("generate collaboration from access", accessToCollaboration), // V0 -> V1
}
return fmt.Errorf("get: %v", err)
} else if !has {
// If the user table does not exist it is a fresh installation and we
- // can skip all migrations
+ // can skip all migrations.
needsMigration, err := x.IsTableExist("user")
if err != nil {
return err
return err
}
// If the user table is empty it is a fresh installation and we can
- // skip all migrations
+ // skip all migrations.
needsMigration = !isEmpty
}
if !needsMigration {
return nil
}
+func sessionRelease(sess *xorm.Session) {
+ if !sess.IsCommitedOrRollbacked {
+ sess.Rollback()
+ }
+ sess.Close()
+}
+
func accessToCollaboration(x *xorm.Engine) error {
type Collaboration struct {
ID int64 `xorm:"pk autoincr"`
}
sess := x.NewSession()
- defer func() {
- if sess.IsCommitedOrRollbacked {
- sess.Rollback()
- }
- sess.Close()
- }()
+ defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}