From 9b50743965e7f487f2db3735b12aa22378d68d7a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 30 Aug 2025 17:44:03 -0700 Subject: [PATCH 1/7] extend comment treepath length --- models/issues/comment.go | 4 ++-- models/migrations/migrations.go | 1 + models/migrations/v1_25/v322.go | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 models/migrations/v1_25/v322.go diff --git a/models/issues/comment.go b/models/issues/comment.go index a366b7c6a9ce5..d23b7062fd2d9 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -279,8 +279,8 @@ type Comment struct { DependentIssue *Issue `xorm:"-"` CommitID int64 - Line int64 // - previous line / + proposed line - TreePath string + Line int64 // - previous line / + proposed line + TreePath string `xorm:"VARCHAR(1024)"` Content string `xorm:"LONGTEXT"` ContentVersion int `xorm:"NOT NULL DEFAULT 0"` RenderedContent template.HTML `xorm:"-"` diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 88967a8b870d9..59ca8f91e9fa6 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -393,6 +393,7 @@ func prepareMigrationTasks() []*migration { // Gitea 1.24.0 ends at database version 321 newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs), + newMigration(322, "Extend comment treepath length to 1024", v1_25.ExtendCommentTreePathLength), } return preparedMigrations } diff --git a/models/migrations/v1_25/v322.go b/models/migrations/v1_25/v322.go new file mode 100644 index 0000000000000..af8acc0fbc28a --- /dev/null +++ b/models/migrations/v1_25/v322.go @@ -0,0 +1,14 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_25 + +import "xorm.io/xorm" + +func ExtendCommentTreePathLength(x *xorm.Engine) error { + type Comment struct { + TreePath string `xorm:"VARCHAR(1024)"` + } + + return x.Sync(new(Comment)) +} From f3c42bc4dd3b30507e869dd89615a45705b485ad Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 30 Aug 2025 18:39:29 -0700 Subject: [PATCH 2/7] Use 4096 --- models/issues/comment.go | 2 +- models/migrations/v1_25/v322.go | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index d23b7062fd2d9..a10bcde621fe6 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -280,7 +280,7 @@ type Comment struct { CommitID int64 Line int64 // - previous line / + proposed line - TreePath string `xorm:"VARCHAR(1024)"` + TreePath string `xorm:"VARCHAR(4096)"` Content string `xorm:"LONGTEXT"` ContentVersion int `xorm:"NOT NULL DEFAULT 0"` RenderedContent template.HTML `xorm:"-"` diff --git a/models/migrations/v1_25/v322.go b/models/migrations/v1_25/v322.go index af8acc0fbc28a..a292e2e2b4a39 100644 --- a/models/migrations/v1_25/v322.go +++ b/models/migrations/v1_25/v322.go @@ -3,12 +3,21 @@ package v1_25 -import "xorm.io/xorm" +import ( + "code.gitea.io/gitea/models/migrations/base" -func ExtendCommentTreePathLength(x *xorm.Engine) error { - type Comment struct { - TreePath string `xorm:"VARCHAR(1024)"` - } + "xorm.io/xorm" + "xorm.io/xorm/schemas" +) - return x.Sync(new(Comment)) +func ExtendCommentTreePathLength(x *xorm.Engine) error { + return base.ModifyColumn(x, "comment", &schemas.Column{ + Name: "tree_path", + SQLType: schemas.SQLType{ + Name: "VARCHAR", + }, + Length: 4096, + Nullable: true, // To keep compatible as nullable + DefaultIsEmpty: true, + }) } From e15e205b94c48e47e6b06dff099de0e4a5300461 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 31 Aug 2025 12:29:07 +0800 Subject: [PATCH 3/7] Update models/migrations/migrations.go Signed-off-by: wxiaoguang --- models/migrations/migrations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 59ca8f91e9fa6..1b1558f39d1ce 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -393,7 +393,7 @@ func prepareMigrationTasks() []*migration { // Gitea 1.24.0 ends at database version 321 newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs), - newMigration(322, "Extend comment treepath length to 1024", v1_25.ExtendCommentTreePathLength), + newMigration(322, "Extend comment tree_path length limit", v1_25.ExtendCommentTreePathLength), } return preparedMigrations } From 0b7cc6b194d70c3f2e0be257b7aa13c267166ea5 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 31 Aug 2025 12:29:13 +0800 Subject: [PATCH 4/7] Update models/migrations/v1_25/v322.go Signed-off-by: wxiaoguang --- models/migrations/v1_25/v322.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_25/v322.go b/models/migrations/v1_25/v322.go index a292e2e2b4a39..119ba30cb7648 100644 --- a/models/migrations/v1_25/v322.go +++ b/models/migrations/v1_25/v322.go @@ -16,7 +16,7 @@ func ExtendCommentTreePathLength(x *xorm.Engine) error { SQLType: schemas.SQLType{ Name: "VARCHAR", }, - Length: 4096, + Length: 4000, Nullable: true, // To keep compatible as nullable DefaultIsEmpty: true, }) From e1a92c5fc6ca95a6a3badcd8fd9914552a89d9fe Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 31 Aug 2025 12:29:19 +0800 Subject: [PATCH 5/7] Update models/issues/comment.go Signed-off-by: wxiaoguang --- models/issues/comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index a10bcde621fe6..63a39607ed347 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -280,7 +280,7 @@ type Comment struct { CommitID int64 Line int64 // - previous line / + proposed line - TreePath string `xorm:"VARCHAR(4096)"` + TreePath string `xorm:"VARCHAR(4096)"` // SQLServer only supports up to 4000 Content string `xorm:"LONGTEXT"` ContentVersion int `xorm:"NOT NULL DEFAULT 0"` RenderedContent template.HTML `xorm:"-"` From f4d282fc7f83d29508fccf46e78f81573c3fa5b1 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 31 Aug 2025 12:29:41 +0800 Subject: [PATCH 6/7] Update models/issues/comment.go Signed-off-by: wxiaoguang --- models/issues/comment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index 63a39607ed347..3a4049700de1a 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -280,7 +280,7 @@ type Comment struct { CommitID int64 Line int64 // - previous line / + proposed line - TreePath string `xorm:"VARCHAR(4096)"` // SQLServer only supports up to 4000 + TreePath string `xorm:"VARCHAR(4000)"` // SQLServer only supports up to 4000 Content string `xorm:"LONGTEXT"` ContentVersion int `xorm:"NOT NULL DEFAULT 0"` RenderedContent template.HTML `xorm:"-"` From 61479b667a68f5c78922b5549abd6c6c801269a8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 31 Aug 2025 21:10:06 -0700 Subject: [PATCH 7/7] Fix bug --- models/migrations/v1_25/v322.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/migrations/v1_25/v322.go b/models/migrations/v1_25/v322.go index 119ba30cb7648..32dae9945ae8e 100644 --- a/models/migrations/v1_25/v322.go +++ b/models/migrations/v1_25/v322.go @@ -11,6 +11,11 @@ import ( ) func ExtendCommentTreePathLength(x *xorm.Engine) 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{ Name: "tree_path", SQLType: schemas.SQLType{