Skip to content

Commit 608cd54

Browse files
lunnybkcsoft
authored andcommitted
fix gpg wrong column types
1 parent 430cc4f commit 608cd54

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

models/gpg_key.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
type GPGKey struct {
2121
ID int64 `xorm:"pk autoincr"`
2222
OwnerID int64 `xorm:"INDEX NOT NULL"`
23-
KeyID string `xorm:"INDEX TEXT NOT NULL"`
24-
PrimaryKeyID string `xorm:"TEXT"`
23+
KeyID string `xorm:"INDEX CHAR(16) NOT NULL"`
24+
PrimaryKeyID string `xorm:"CHAR(16)"`
2525
Content string `xorm:"TEXT NOT NULL"`
2626
Created time.Time `xorm:"-"`
2727
CreatedUnix int64

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ var migrations = []Migration{
9696
NewMigration("generate and migrate wiki Git hooks", generateAndMigrateWikiGitHooks),
9797
// v23 -> v24
9898
NewMigration("add user openid table", addUserOpenID),
99+
// v24 -> v25
100+
NewMigration("change the key_id and primary_key_id type", changeGPGKeysColumns),
99101
}
100102

101103
// Migrate database to current version

models/migrations/v24.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2017 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+
"time"
9+
10+
"github.com/go-xorm/xorm"
11+
)
12+
13+
func changeGPGKeysColumns(x *xorm.Engine) error {
14+
// EmailAddress is the list of all email addresses of a user. Can contain the
15+
// primary email address, but is not obligatory.
16+
type EmailAddress struct {
17+
ID int64 `xorm:"pk autoincr"`
18+
UID int64 `xorm:"INDEX NOT NULL"`
19+
Email string `xorm:"UNIQUE NOT NULL"`
20+
IsActivated bool
21+
IsPrimary bool `xorm:"-"`
22+
}
23+
24+
// GPGKey represents a GPG key.
25+
type GPGKey struct {
26+
ID int64 `xorm:"pk autoincr"`
27+
OwnerID int64 `xorm:"INDEX NOT NULL"`
28+
KeyID string `xorm:"INDEX CHAR(16) NOT NULL"`
29+
PrimaryKeyID string `xorm:"CHAR(16)"`
30+
Content string `xorm:"TEXT NOT NULL"`
31+
Created time.Time `xorm:"-"`
32+
CreatedUnix int64
33+
Expired time.Time `xorm:"-"`
34+
ExpiredUnix int64
35+
Added time.Time `xorm:"-"`
36+
AddedUnix int64
37+
SubsKey []*GPGKey `xorm:"-"`
38+
Emails []*EmailAddress
39+
CanSign bool
40+
CanEncryptComms bool
41+
CanEncryptStorage bool
42+
CanCertify bool
43+
}
44+
45+
if err := x.DropTables(new(GPGKey)); err != nil {
46+
return err
47+
}
48+
49+
return x.Sync(new(GPGKey))
50+
}

0 commit comments

Comments
 (0)