summaryrefslogtreecommitdiffstats
path: root/models/migrations/v40.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-12-13 16:52:18 +0200
committerGitHub <noreply@github.com>2017-12-13 16:52:18 +0200
commitc06cc740dea46f3aff58e0eded4208232bb5902d (patch)
tree8f17cf90828fb06133a14cdee2df67ea6db75550 /models/migrations/v40.go
parentd3c5911ffce8758d020b301e667869aa2e80ce6a (diff)
downloadgitea-c06cc740dea46f3aff58e0eded4208232bb5902d.tar.gz
gitea-c06cc740dea46f3aff58e0eded4208232bb5902d.zip
Reorder migrations, skip errors if running migration again (#3160)
* Reorder migrations, skip errors if running migration again * Rename migration file names to match migration version * Add note about ingored error
Diffstat (limited to 'models/migrations/v40.go')
-rw-r--r--models/migrations/v40.go45
1 files changed, 8 insertions, 37 deletions
diff --git a/models/migrations/v40.go b/models/migrations/v40.go
index 324521e0b6..fffe158bf9 100644
--- a/models/migrations/v40.go
+++ b/models/migrations/v40.go
@@ -6,50 +6,21 @@ package migrations
import (
"fmt"
- "time"
-
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
"github.com/go-xorm/xorm"
)
-func migrateProtectedBranchStruct(x *xorm.Engine) error {
+func fixProtectedBranchCanPushValue(x *xorm.Engine) error {
type ProtectedBranch struct {
- ID int64 `xorm:"pk autoincr"`
- RepoID int64 `xorm:"UNIQUE(s)"`
- BranchName string `xorm:"UNIQUE(s)"`
- CanPush bool
- Created time.Time `xorm:"-"`
- CreatedUnix int64
- Updated time.Time `xorm:"-"`
- UpdatedUnix int64
- }
-
- var pbs []ProtectedBranch
- err := x.Find(&pbs)
- if err != nil {
- return err
- }
-
- for _, pb := range pbs {
- if pb.CanPush {
- if _, err = x.ID(pb.ID).Delete(new(ProtectedBranch)); err != nil {
- return err
- }
- }
+ CanPush bool `xorm:"NOT NULL DEFAULT false"`
}
- switch {
- case setting.UseSQLite3:
- log.Warn("Unable to drop columns in SQLite")
- case setting.UseMySQL, setting.UsePostgreSQL, setting.UseMSSQL, setting.UseTiDB:
- if _, err := x.Exec("ALTER TABLE protected_branch DROP COLUMN can_push"); err != nil {
- return fmt.Errorf("DROP COLUMN can_push: %v", err)
- }
- default:
- log.Fatal(4, "Unrecognized DB")
+ if err := x.Sync2(new(ProtectedBranch)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
}
- return nil
+ _, err := x.Cols("can_push").Update(&ProtectedBranch{
+ CanPush: false,
+ })
+ return err
}