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.

v78.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "github.com/go-xorm/core"
  10. "github.com/go-xorm/xorm"
  11. )
  12. func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
  13. type Repository struct {
  14. ID int64 `xorm:"pk autoincr"`
  15. IsBare bool
  16. IsEmpty bool `xorm:"INDEX"`
  17. }
  18. // First remove the index
  19. sess := x.NewSession()
  20. defer sess.Close()
  21. if err := sess.Begin(); err != nil {
  22. return err
  23. }
  24. var err error
  25. if models.DbCfg.Type == core.POSTGRES || models.DbCfg.Type == core.SQLITE {
  26. _, err = sess.Exec("DROP INDEX IF EXISTS IDX_repository_is_bare")
  27. } else {
  28. _, err = sess.Exec("DROP INDEX IDX_repository_is_bare ON repository")
  29. }
  30. if err != nil {
  31. return fmt.Errorf("Drop index failed: %v", err)
  32. }
  33. if err = sess.Commit(); err != nil {
  34. return err
  35. }
  36. // Then reset the values
  37. sess = x.NewSession()
  38. defer sess.Close()
  39. if err := sess.Begin(); err != nil {
  40. return err
  41. }
  42. if err := sess.Sync2(new(Repository)); err != nil {
  43. return err
  44. }
  45. if _, err := sess.Exec("UPDATE repository SET is_empty = is_bare;"); err != nil {
  46. return err
  47. }
  48. if models.DbCfg.Type != core.SQLITE {
  49. _, err = sess.Exec("ALTER TABLE repository DROP COLUMN is_bare")
  50. if err != nil {
  51. return fmt.Errorf("Drop column failed: %v", err)
  52. }
  53. }
  54. if err = sess.Commit(); err != nil {
  55. return err
  56. }
  57. if models.DbCfg.Type == core.SQLITE {
  58. log.Warn("TABLE repository's COLUMN is_bare should be DROP but sqlite is not supported, you could manually do that.")
  59. }
  60. return nil
  61. }