Skip to content

Commit 52dd383

Browse files
authored
Increase Content field size of gpg_key_import to MEDIUMTEXT (#22897)
Unfortunately #20896 does not completely prevent Data too long issues and GPGKeyImport needs to be increased too. Fix #22896 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f196da1 commit 52dd383

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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() {

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_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText),
460462
}
461463

462464
// GetCurrentDBVersion returns the current db version

models/migrations/v1_19/v242.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023 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+
9+
"xorm.io/xorm"
10+
)
11+
12+
// AlterPublicGPGKeyImportContentFieldToMediumText: set GPGKeyImport Content field to MEDIUMTEXT
13+
func AlterPublicGPGKeyImportContentFieldToMediumText(x *xorm.Engine) error {
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 `gpg_key_import` CHANGE `content` `content` MEDIUMTEXT"); err != nil {
22+
return err
23+
}
24+
}
25+
return sess.Commit()
26+
}

0 commit comments

Comments
 (0)