本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

84 lines
2.1KB

  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. "net/url"
  7. "strings"
  8. "time"
  9. "xorm.io/xorm"
  10. )
  11. func updateMigrationServiceTypes(x *xorm.Engine) error {
  12. type Repository struct {
  13. ID int64
  14. OriginalServiceType int `xorm:"index default(0)"`
  15. OriginalURL string `xorm:"VARCHAR(2048)"`
  16. FundingToCollaboration int64
  17. }
  18. if err := x.Sync2(new(Repository)); err != nil {
  19. return err
  20. }
  21. var last int
  22. const batchSize = 50
  23. for {
  24. var results = make([]Repository, 0, batchSize)
  25. err := x.Where("original_url <> '' AND original_url IS NOT NULL").
  26. And("original_service_type = 0 OR original_service_type IS NULL").
  27. OrderBy("id").
  28. Limit(batchSize, last).
  29. Find(&results)
  30. if err != nil {
  31. return err
  32. }
  33. if len(results) == 0 {
  34. break
  35. }
  36. last += len(results)
  37. const PlainGitService = 1 // 1 plain git service
  38. const GithubService = 2 // 2 github.com
  39. for _, res := range results {
  40. u, err := url.Parse(res.OriginalURL)
  41. if err != nil {
  42. return err
  43. }
  44. var serviceType = PlainGitService
  45. if strings.EqualFold(u.Host, "github.com") {
  46. serviceType = GithubService
  47. }
  48. _, err = x.Exec("UPDATE repository SET original_service_type = ? WHERE id = ?", serviceType, res.ID)
  49. if err != nil {
  50. return err
  51. }
  52. }
  53. }
  54. type ExternalLoginUser struct {
  55. ExternalID string `xorm:"pk NOT NULL"`
  56. UserID int64 `xorm:"INDEX NOT NULL"`
  57. LoginSourceID int64 `xorm:"pk NOT NULL"`
  58. RawData map[string]interface{} `xorm:"TEXT JSON"`
  59. Provider string `xorm:"index VARCHAR(25)"`
  60. Email string
  61. Name string
  62. FirstName string
  63. LastName string
  64. NickName string
  65. Description string
  66. AvatarURL string
  67. Location string
  68. AccessToken string
  69. AccessTokenSecret string
  70. RefreshToken string
  71. ExpiresAt time.Time
  72. }
  73. return x.Sync2(new(ExternalLoginUser))
  74. }
上海开阖软件有限公司 沪ICP备12045867号-1