Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter issue/comment table TEXT fields to LONGTEXT #16765

Merged
merged 4 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions models/migrations/v191.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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
}

if 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
}
}
return sess.Commit()
}