summaryrefslogtreecommitdiffstats
path: root/models/migrations
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2015-02-12 12:46:21 -0500
committerUnknwon <joe2010xtmf@163.com>2015-02-12 12:46:21 -0500
commit0b3722c3592ce79b2d0a5ea461366587d91250a5 (patch)
tree3eb63ebf0d9d97ea58204897b45fab0a0c1586d4 /models/migrations
parent31eb49c3ae86ab26703c420a8f4e11ccde1780d3 (diff)
downloadgitea-0b3722c3592ce79b2d0a5ea461366587d91250a5.tar.gz
gitea-0b3722c3592ce79b2d0a5ea461366587d91250a5.zip
models/migrations: fix little logic error
Diffstat (limited to 'models/migrations')
-rw-r--r--models/migrations/migrations.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 814564e9af..ba2ec0cd0a 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -47,8 +47,8 @@ type Version struct {
}
// 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
}
@@ -65,7 +65,7 @@ func Migrate(x *xorm.Engine) error {
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
@@ -76,7 +76,7 @@ func Migrate(x *xorm.Engine) error {
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 {
@@ -102,6 +102,13 @@ func Migrate(x *xorm.Engine) error {
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"`
@@ -118,12 +125,7 @@ func accessToCollaboration(x *xorm.Engine) error {
}
sess := x.NewSession()
- defer func() {
- if sess.IsCommitedOrRollbacked {
- sess.Rollback()
- }
- sess.Close()
- }()
+ defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}