|
| 1 | +// Copyright 2025 The Gitea Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package v1_25 |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "code.gitea.io/gitea/models/migrations/base" |
| 10 | + "code.gitea.io/gitea/modules/setting" |
| 11 | + "code.gitea.io/gitea/modules/timeutil" |
| 12 | + |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | +) |
| 15 | + |
| 16 | +func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) { |
| 17 | + if !setting.Database.Type.IsMySQL() { |
| 18 | + t.Skip("Only MySQL needs to change from TEXT to LONGTEXT") |
| 19 | + } |
| 20 | + |
| 21 | + type ReviewState struct { |
| 22 | + ID int64 `xorm:"pk autoincr"` |
| 23 | + UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"` |
| 24 | + PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"` // Which PR was the review on? |
| 25 | + CommitSHA string `xorm:"NOT NULL VARCHAR(64) UNIQUE(pull_commit_user)"` // Which commit was the head commit for the review? |
| 26 | + 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 |
| 27 | + 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 |
| 28 | + } |
| 29 | + |
| 30 | + type PackageProperty struct { |
| 31 | + ID int64 `xorm:"pk autoincr"` |
| 32 | + RefType int `xorm:"INDEX NOT NULL"` |
| 33 | + RefID int64 `xorm:"INDEX NOT NULL"` |
| 34 | + Name string `xorm:"INDEX NOT NULL"` |
| 35 | + Value string `xorm:"TEXT NOT NULL"` |
| 36 | + } |
| 37 | + |
| 38 | + type Notice struct { |
| 39 | + ID int64 `xorm:"pk autoincr"` |
| 40 | + Type int |
| 41 | + Description string `xorm:"LONGTEXT"` |
| 42 | + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` |
| 43 | + } |
| 44 | + |
| 45 | + // Prepare and load the testing database |
| 46 | + x, deferable := base.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice)) |
| 47 | + defer deferable() |
| 48 | + |
| 49 | + assert.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x)) |
| 50 | + |
| 51 | + tables, err := x.DBMetas() |
| 52 | + assert.NoError(t, err) |
| 53 | + |
| 54 | + for _, table := range tables { |
| 55 | + switch table.Name { |
| 56 | + case "review_state": |
| 57 | + column := table.GetColumn("updated_files") |
| 58 | + assert.NotNil(t, column) |
| 59 | + assert.Equal(t, "LONGTEXT", column.SQLType.Name) |
| 60 | + case "package_property": |
| 61 | + column := table.GetColumn("value") |
| 62 | + assert.NotNil(t, column) |
| 63 | + assert.Equal(t, "LONGTEXT", column.SQLType.Name) |
| 64 | + case "notice": |
| 65 | + column := table.GetColumn("description") |
| 66 | + assert.NotNil(t, column) |
| 67 | + assert.Equal(t, "LONGTEXT", column.SQLType.Name) |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments