You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

v40.go 1.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "fmt"
  7. "time"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/go-xorm/xorm"
  11. )
  12. func migrateProtectedBranchStruct(x *xorm.Engine) error {
  13. type ProtectedBranch struct {
  14. ID int64 `xorm:"pk autoincr"`
  15. RepoID int64 `xorm:"UNIQUE(s)"`
  16. BranchName string `xorm:"UNIQUE(s)"`
  17. CanPush bool
  18. Created time.Time `xorm:"-"`
  19. CreatedUnix int64
  20. Updated time.Time `xorm:"-"`
  21. UpdatedUnix int64
  22. }
  23. var pbs []ProtectedBranch
  24. err := x.Find(&pbs)
  25. if err != nil {
  26. return err
  27. }
  28. for _, pb := range pbs {
  29. if pb.CanPush {
  30. if _, err = x.ID(pb.ID).Delete(new(ProtectedBranch)); err != nil {
  31. return err
  32. }
  33. }
  34. }
  35. switch {
  36. case setting.UseSQLite3:
  37. log.Warn("Unable to drop columns in SQLite")
  38. case setting.UseMySQL, setting.UsePostgreSQL, setting.UseMSSQL, setting.UseTiDB:
  39. if _, err := x.Exec("ALTER TABLE protected_branch DROP COLUMN can_push"); err != nil {
  40. return fmt.Errorf("DROP COLUMN can_push: %v", err)
  41. }
  42. default:
  43. log.Fatal(4, "Unrecognized DB")
  44. }
  45. return nil
  46. }