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
This commit is contained in:
Lauris BH 2017-12-13 16:52:18 +02:00 committed by GitHub
parent d3c5911ffc
commit c06cc740de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 303 additions and 294 deletions

View file

@ -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
CanPush bool `xorm:"NOT NULL DEFAULT false"`
}
var pbs []ProtectedBranch
err := x.Find(&pbs)
if err != nil {
return err
if err := x.Sync2(new(ProtectedBranch)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
for _, pb := range pbs {
if pb.CanPush {
if _, err = x.ID(pb.ID).Delete(new(ProtectedBranch)); err != nil {
return err
}
}
}
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")
}
return nil
_, err := x.Cols("can_push").Update(&ProtectedBranch{
CanPush: false,
})
return err
}