Skip to content

Commit 6e0f2e9

Browse files
committed
Alter issue/comment table TEXT fields to LONGTEXT
1 parent 0bd58d6 commit 6e0f2e9

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

models/issue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Issue struct {
3636
OriginalAuthor string
3737
OriginalAuthorID int64 `xorm:"index"`
3838
Title string `xorm:"name"`
39-
Content string `xorm:"TEXT"`
39+
Content string `xorm:"LONGTEXT"`
4040
RenderedContent string `xorm:"-"`
4141
Labels []*Label `xorm:"-"`
4242
MilestoneID int64 `xorm:"INDEX"`

models/issue_comment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ type Comment struct {
155155
CommitID int64
156156
Line int64 // - previous line / + proposed line
157157
TreePath string
158-
Content string `xorm:"TEXT"`
158+
Content string `xorm:"LONGTEXT"`
159159
RenderedContent string `xorm:"-"`
160160

161161
// Path represents the 4 lines of code cemented by this comment
162162
Patch string `xorm:"-"`
163-
PatchQuoted string `xorm:"TEXT patch"`
163+
PatchQuoted string `xorm:"LONGTEXT patch"`
164164

165165
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
166166
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ var migrations = []Migration{
334334
NewMigration("Unwrap ldap.Sources", unwrapLDAPSourceCfg),
335335
// v190 -> v191
336336
NewMigration("Add agit flow pull request support", addAgitFlowPullRequest),
337+
// v191 -> v192
338+
NewMigration("Alter issue/comment table TEXT fields to LONGTEXT", alterIssueAndCommentTextFieldsToLongText),
337339
}
338340

339341
// GetCurrentDBVersion returns the current db version

models/migrations/v191.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2021 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+
5+
package migrations
6+
7+
import (
8+
"code.gitea.io/gitea/modules/setting"
9+
"xorm.io/xorm"
10+
)
11+
12+
func alterIssueAndCommentTextFieldsToLongText(x *xorm.Engine) error {
13+
14+
sess := x.NewSession()
15+
defer sess.Close()
16+
if err := sess.Begin(); err != nil {
17+
return err
18+
}
19+
20+
switch {
21+
case setting.Database.UseMySQL:
22+
if _, err := sess.Exec("ALTER TABLE `issue` CHANGE `content` `content` LONGTEXT"); err != nil {
23+
return err
24+
}
25+
if _, err := sess.Exec("ALTER TABLE `comment` CHANGE `content` `content` LONGTEXT, CHANGE `patch` `patch` LONGTEXT"); err != nil {
26+
return err
27+
}
28+
default:
29+
// only MySQL needs to widen the TEXT limitation. pgsql/mssql/sqlite do not have such limitation.
30+
}
31+
return sess.Commit()
32+
}

0 commit comments

Comments
 (0)