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

v50.go 1.3KB

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. "time"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/modules/setting"
  9. "xorm.io/xorm"
  10. )
  11. func migrateProtectedBranchStruct(x *xorm.Engine) error {
  12. type ProtectedBranch struct {
  13. ID int64 `xorm:"pk autoincr"`
  14. RepoID int64 `xorm:"UNIQUE(s)"`
  15. BranchName string `xorm:"UNIQUE(s)"`
  16. CanPush bool
  17. Created time.Time `xorm:"-"`
  18. CreatedUnix int64
  19. Updated time.Time `xorm:"-"`
  20. UpdatedUnix int64
  21. }
  22. var pbs []ProtectedBranch
  23. err := x.Find(&pbs)
  24. if err != nil {
  25. return err
  26. }
  27. for _, pb := range pbs {
  28. if pb.CanPush {
  29. if _, err = x.ID(pb.ID).Delete(new(ProtectedBranch)); err != nil {
  30. return err
  31. }
  32. }
  33. }
  34. switch {
  35. case setting.Database.UseSQLite3:
  36. log.Warn("Unable to drop columns in SQLite")
  37. case setting.Database.UseMySQL, setting.Database.UsePostgreSQL, setting.Database.UseMSSQL:
  38. if _, err := x.Exec("ALTER TABLE protected_branch DROP COLUMN can_push"); err != nil {
  39. // Ignoring this error in case we run this migration second time (after migration reordering)
  40. log.Warn("DROP COLUMN can_push (skipping): %v", err)
  41. }
  42. default:
  43. log.Fatal("Unrecognized DB")
  44. }
  45. return nil
  46. }