summaryrefslogtreecommitdiffstats
path: root/models/migrations/v78.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-01-18 00:01:04 +0000
committertechknowlogick <hello@techknowlogick.com>2019-01-17 19:01:04 -0500
commit07802a2bc503a8c13d50e7ef04a0e13ccf2a90f8 (patch)
tree87ced90635366b09e7e5f2634acfe2cbec2bc9f6 /models/migrations/v78.go
parent9edc829c1758b436f8f52ebe61479af087940d60 (diff)
downloadgitea-07802a2bc503a8c13d50e7ef04a0e13ccf2a90f8.tar.gz
gitea-07802a2bc503a8c13d50e7ef04a0e13ccf2a90f8.zip
Refactor repo.isBare to repo.isEmpty #5629 (#5714)
* Refactor repo.isBare to repo.isEmpty #5629 Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove Sync call
Diffstat (limited to 'models/migrations/v78.go')
-rw-r--r--models/migrations/v78.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/models/migrations/v78.go b/models/migrations/v78.go
new file mode 100644
index 0000000000..d2b637da5e
--- /dev/null
+++ b/models/migrations/v78.go
@@ -0,0 +1,42 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "fmt"
+ "strings"
+
+ "code.gitea.io/gitea/models"
+
+ "github.com/go-xorm/xorm"
+)
+
+func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
+ type Repository struct {
+ ID int64 `xorm:"pk autoincr"`
+ IsBare bool
+ IsEmpty bool `xorm:"INDEX"`
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+ var err error
+ if models.DbCfg.Type == "mssql" {
+ _, err = sess.Query("EXEC sp_rename 'repository.is_bare', 'is_empty', 'COLUMN'")
+ } else {
+ _, err = sess.Query("ALTER TABLE \"repository\" RENAME COLUMN \"is_bare\" TO \"is_empty\";")
+ }
+ if err != nil {
+ if strings.Contains(err.Error(), "no such column") {
+ return nil
+ }
+ return fmt.Errorf("select repositories: %v", err)
+ }
+
+ return sess.Commit()
+}