Skip to content

Commit

Permalink
Alter issue/comment table TEXT fields to LONGTEXT
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Aug 21, 2021
1 parent 0bd58d6 commit 6e0f2e9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Issue struct {
OriginalAuthor string
OriginalAuthorID int64 `xorm:"index"`
Title string `xorm:"name"`
Content string `xorm:"TEXT"`
Content string `xorm:"LONGTEXT"`
RenderedContent string `xorm:"-"`
Labels []*Label `xorm:"-"`
MilestoneID int64 `xorm:"INDEX"`
Expand Down
4 changes: 2 additions & 2 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ type Comment struct {
CommitID int64
Line int64 // - previous line / + proposed line
TreePath string
Content string `xorm:"TEXT"`
Content string `xorm:"LONGTEXT"`
RenderedContent string `xorm:"-"`

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

CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ var migrations = []Migration{
NewMigration("Unwrap ldap.Sources", unwrapLDAPSourceCfg),
// v190 -> v191
NewMigration("Add agit flow pull request support", addAgitFlowPullRequest),
// v191 -> v192
NewMigration("Alter issue/comment table TEXT fields to LONGTEXT", alterIssueAndCommentTextFieldsToLongText),
}

// GetCurrentDBVersion returns the current db version
Expand Down
32 changes: 32 additions & 0 deletions models/migrations/v191.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"code.gitea.io/gitea/modules/setting"
"xorm.io/xorm"
)

func alterIssueAndCommentTextFieldsToLongText(x *xorm.Engine) error {

sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}

switch {
case setting.Database.UseMySQL:
if _, err := sess.Exec("ALTER TABLE `issue` CHANGE `content` `content` LONGTEXT"); err != nil {
return err
}
if _, err := sess.Exec("ALTER TABLE `comment` CHANGE `content` `content` LONGTEXT, CHANGE `patch` `patch` LONGTEXT"); err != nil {
return err
}
default:
// only MySQL needs to widen the TEXT limitation. pgsql/mssql/sqlite do not have such limitation.
}
return sess.Commit()
}

0 comments on commit 6e0f2e9

Please sign in to comment.