Skip to content

Commit b55c699

Browse files
wxiaoguangzeripath
andauthoredAug 22, 2021
Alter issue/comment table TEXT fields to LONGTEXT (#16765)
* Alter issue/comment table TEXT fields to LONGTEXT * Use If not Switch Co-authored-by: zeripath <art27@cantab.net>
1 parent 7f85610 commit b55c699

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-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

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
if setting.Database.UseMySQL {
21+
if _, err := sess.Exec("ALTER TABLE `issue` CHANGE `content` `content` LONGTEXT"); err != nil {
22+
return err
23+
}
24+
if _, err := sess.Exec("ALTER TABLE `comment` CHANGE `content` `content` LONGTEXT, CHANGE `patch` `patch` LONGTEXT"); err != nil {
25+
return err
26+
}
27+
}
28+
return sess.Commit()
29+
}

0 commit comments

Comments
 (0)
Please sign in to comment.