refactor(modelmigration): thread context through migration functions (#38758)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-08-03 08:13:15 +00:00
committed by GitHub
co-authored by wxiaoguang
parent e23fe79e5e
commit ac49dbe1a2
304 changed files with 1070 additions and 449 deletions
+6 -4
View File
@@ -4,18 +4,20 @@
package v1_25
import (
"context"
"gitea.dev/modelmigration/base"
"gitea.dev/modules/setting"
"xorm.io/xorm/schemas"
)
func UseLongTextInSomeColumnsAndFixBugs(x base.EngineMigration) error {
func UseLongTextInSomeColumnsAndFixBugs(ctx context.Context, x base.EngineMigration) error {
if !setting.Database.Type.IsMySQL() {
return nil // Only mysql need to change from text to long text, for other databases, they are the same
}
if err := base.ModifyColumn(x, "review_state", &schemas.Column{
if err := base.ModifyColumn(ctx, x, "review_state", &schemas.Column{
Name: "updated_files",
SQLType: schemas.SQLType{
Name: "LONGTEXT",
@@ -27,7 +29,7 @@ func UseLongTextInSomeColumnsAndFixBugs(x base.EngineMigration) error {
return err
}
if err := base.ModifyColumn(x, "package_property", &schemas.Column{
if err := base.ModifyColumn(ctx, x, "package_property", &schemas.Column{
Name: "value",
SQLType: schemas.SQLType{
Name: "LONGTEXT",
@@ -39,7 +41,7 @@ func UseLongTextInSomeColumnsAndFixBugs(x base.EngineMigration) error {
return err
}
return base.ModifyColumn(x, "notice", &schemas.Column{
return base.ModifyColumn(ctx, x, "notice", &schemas.Column{
Name: "description",
SQLType: schemas.SQLType{
Name: "LONGTEXT",
+1 -1
View File
@@ -47,7 +47,7 @@ func Test_UseLongTextInSomeColumnsAndFixBugs(t *testing.T) {
x, deferrable := migrationtest.PrepareTestEnv(t, 0, new(ReviewState), new(PackageProperty), new(Notice))
defer deferrable()
require.NoError(t, UseLongTextInSomeColumnsAndFixBugs(x))
require.NoError(t, UseLongTextInSomeColumnsAndFixBugs(t.Context(), x))
tables := migrationtest.LoadTableSchemasMap(t, x)
table := tables["review_state"]
+4 -2
View File
@@ -4,18 +4,20 @@
package v1_25
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm/schemas"
)
func ExtendCommentTreePathLength(x base.EngineMigration) error {
func ExtendCommentTreePathLength(ctx context.Context, x base.EngineMigration) error {
dbType := x.Dialect().URI().DBType
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
return nil
}
return base.ModifyColumn(x, "comment", &schemas.Column{
return base.ModifyColumn(ctx, x, "comment", &schemas.Column{
Name: "tree_path",
SQLType: schemas.SQLType{
Name: "VARCHAR",
+1 -1
View File
@@ -26,7 +26,7 @@ func Test_ExtendCommentTreePathLength(t *testing.T) {
x, deferrable := migrationtest.PrepareTestEnv(t, 0, new(Comment))
defer deferrable()
require.NoError(t, ExtendCommentTreePathLength(x))
require.NoError(t, ExtendCommentTreePathLength(t.Context(), x))
table := migrationtest.LoadTableSchemasMap(t, x)["comment"]
column := table.GetColumn("tree_path")
assert.Contains(t, []string{"NVARCHAR", "VARCHAR"}, column.SQLType.Name)