Skip to content

Commit c6142fb

Browse files
committed
Increase Content field size of gpg_import_key to MEDIUMTEXT
Unfortunately go-gitea#20896 does not completely prevent Data too long issues and GPGImportKey needs to be increased too. Fix go-gitea#22896 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 7b5b739 commit c6142fb

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Diff for: models/asymkey/gpg_key_import.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "code.gitea.io/gitea/models/db"
2323
// GPGKeyImport the original import of key
2424
type GPGKeyImport struct {
2525
KeyID string `xorm:"pk CHAR(16) NOT NULL"`
26-
Content string `xorm:"TEXT NOT NULL"`
26+
Content string `xorm:"MEDIUMTEXT NOT NULL"`
2727
}
2828

2929
func init() {

Diff for: models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ var migrations = []Migration{
457457
NewMigration("Add actions tables", v1_19.AddActionsTables),
458458
// v241 -> v242
459459
NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable),
460+
// v242 -> v243
461+
NewMigration("Alter gpg_import_key content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGImportKeyContentFieldToMediumText),
460462
}
461463

462464
// GetCurrentDBVersion returns the current db version

Diff for: models/migrations/v1_19/v242.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_19 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/setting"
8+
"xorm.io/xorm"
9+
)
10+
11+
// AlterPublicGPGImportKeyContentFieldToMediumText: set GPGImportKey Content field to MEDIUMTEXT
12+
func AlterPublicGPGImportKeyContentFieldToMediumText(x *xorm.Engine) error {
13+
sess := x.NewSession()
14+
defer sess.Close()
15+
if err := sess.Begin(); err != nil {
16+
return err
17+
}
18+
19+
if setting.Database.UseMySQL {
20+
if _, err := sess.Exec("ALTER TABLE `gpg_import_key` CHANGE `content` `content` MEDIUMTEXT"); err != nil {
21+
return err
22+
}
23+
}
24+
return sess.Commit()
25+
}

0 commit comments

Comments
 (0)