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.

42 lines
869 B

  1. // Copyright 2019 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. "xorm.io/xorm"
  7. )
  8. func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
  9. type Repository struct {
  10. ID int64 `xorm:"pk autoincr"`
  11. IsBare bool
  12. IsEmpty bool `xorm:"INDEX"`
  13. }
  14. sess := x.NewSession()
  15. defer sess.Close()
  16. if err := sess.Begin(); err != nil {
  17. return err
  18. }
  19. if err := sess.Sync2(new(Repository)); err != nil {
  20. return err
  21. }
  22. if _, err := sess.Exec("UPDATE repository SET is_empty = is_bare;"); err != nil {
  23. return err
  24. }
  25. if err := sess.Commit(); err != nil {
  26. return err
  27. }
  28. if err := sess.Begin(); err != nil {
  29. return err
  30. }
  31. if err := dropTableColumns(sess, "repository", "is_bare"); err != nil {
  32. return err
  33. }
  34. return sess.Commit()
  35. }