gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_25
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/models/migrations/base"
  7. "code.gitea.io/gitea/modules/setting"
  8. "code.gitea.io/gitea/modules/timeutil"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
  12. if !setting.Database.Type.IsMySQL() {
  13. t.Skip("Only MySQL needs to change from TEXT to LONGTEXT")
  14. }
  15. type ReviewState struct {
  16. ID int64 `xorm:"pk autoincr"`
  17. UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"`
  18. PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"` // Which PR was the review on?
  19. CommitSHA string `xorm:"NOT NULL VARCHAR(64) UNIQUE(pull_commit_user)"` // Which commit was the head commit for the review?
  20. UpdatedFiles map[string]int `xorm:"NOT NULL TEXT JSON"` // Stores for each of the changed files of a PR whether they have been viewed, changed since last viewed, or not viewed
  21. UpdatedUnix timeutil.TimeStamp `xorm:"updated"` // Is an accurate indicator of the order of commits as we do not expect it to be possible to make reviews on previous commits
  22. }
  23. type PackageProperty struct {
  24. ID int64 `xorm:"pk autoincr"`
  25. RefType int `xorm:"INDEX NOT NULL"`
  26. RefID int64 `xorm:"INDEX NOT NULL"`
  27. Name string `xorm:"INDEX NOT NULL"`
  28. Value string `xorm:"TEXT NOT NULL"`
  29. }
  30. type Notice struct {
  31. ID int64 `xorm:"pk autoincr"`
  32. Type int
  33. Description string `xorm:"LONGTEXT"`
  34. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  35. }
  36. // Prepare and load the testing database
  37. x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
  38. defer deferable()
  39. assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
  40. tables, err := x.DBMetas()
  41. assert.NoError(t, err)
  42. for _, table := range tables {
  43. switch table.Name {
  44. case "review_state":
  45. column := table.GetColumn("updated_files")
  46. assert.NotNil(t, column)
  47. assert.Equal(t, "LONGTEXT", column.SQLType.Name)
  48. case "package_property":
  49. column := table.GetColumn("value")
  50. assert.NotNil(t, column)
  51. assert.Equal(t, "LONGTEXT", column.SQLType.Name)
  52. case "notice":
  53. column := table.GetColumn("description")
  54. assert.NotNil(t, column)
  55. assert.Equal(t, "LONGTEXT", column.SQLType.Name)
  56. }
  57. }
  58. }