Skip to content

Commit 33ab4d6

Browse files
zeripathSysoev, Vladimir
authored and
Sysoev, Vladimir
committed
Increase Content field size of gpg_key and public_key to MEDIUMTEXT (go-gitea#20896)
Unfortunately some keys are too big to fix within the 65535 limit of TEXT on MySQL this causes issues with these large keys. Therefore increase these fields to MEDIUMTEXT. Fix go-gitea#20894 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 09bda24 commit 33ab4d6

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

models/asymkey/gpg_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type GPGKey struct {
3333
OwnerID int64 `xorm:"INDEX NOT NULL"`
3434
KeyID string `xorm:"INDEX CHAR(16) NOT NULL"`
3535
PrimaryKeyID string `xorm:"CHAR(16)"`
36-
Content string `xorm:"TEXT NOT NULL"`
36+
Content string `xorm:"MEDIUMTEXT NOT NULL"`
3737
CreatedUnix timeutil.TimeStamp `xorm:"created"`
3838
ExpiredUnix timeutil.TimeStamp
3939
AddedUnix timeutil.TimeStamp

models/asymkey/ssh_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type PublicKey struct {
4141
OwnerID int64 `xorm:"INDEX NOT NULL"`
4242
Name string `xorm:"NOT NULL"`
4343
Fingerprint string `xorm:"INDEX NOT NULL"`
44-
Content string `xorm:"TEXT NOT NULL"`
44+
Content string `xorm:"MEDIUMTEXT NOT NULL"`
4545
Mode perm.AccessMode `xorm:"NOT NULL DEFAULT 2"`
4646
Type KeyType `xorm:"NOT NULL DEFAULT 1"`
4747
LoginSourceID int64 `xorm:"NOT NULL DEFAULT 0"`

models/migrations/migrations.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,13 @@ var migrations = []Migration{
406406
NewMigration("Drop old CredentialID column", dropOldCredentialIDColumn),
407407
// v223 -> v224
408408
NewMigration("Rename CredentialIDBytes column to CredentialID", renameCredentialIDBytes),
409+
410+
// Gitea 1.17.0 ends at v224
411+
409412
// v224 -> v225
410-
NewMigration("Add badges to users", creatUserBadgesTable),
413+
NewMigration("Add badges to users", createUserBadgesTable),
414+
// v225 -> v226
415+
NewMigration("Alter gpg_key/public_key content TEXT fields to MEDIUMTEXT", alterPublicGPGKeyContentFieldsToMediumText),
411416
}
412417

413418
// GetCurrentDBVersion returns the current db version

models/migrations/v224.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"xorm.io/xorm"
99
)
1010

11-
func creatUserBadgesTable(x *xorm.Engine) error {
11+
func createUserBadgesTable(x *xorm.Engine) error {
1212
type Badge struct {
1313
ID int64 `xorm:"pk autoincr"`
1414
Description string

models/migrations/v225.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2022 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+
10+
"xorm.io/xorm"
11+
)
12+
13+
func alterPublicGPGKeyContentFieldsToMediumText(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` CHANGE `content` `content` MEDIUMTEXT"); err != nil {
22+
return err
23+
}
24+
if _, err := sess.Exec("ALTER TABLE `public_key` CHANGE `content` `content` MEDIUMTEXT"); err != nil {
25+
return err
26+
}
27+
}
28+
return sess.Commit()
29+
}

0 commit comments

Comments
 (0)