From 37eee6364eb728c5216d426d97627e94444ed3e3 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 17 Mar 2017 22:24:51 +0800 Subject: [PATCH] fix gpg wrong column types --- models/gpg_key.go | 4 +-- models/migrations/migrations.go | 2 ++ models/migrations/v24.go | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 models/migrations/v24.go diff --git a/models/gpg_key.go b/models/gpg_key.go index 9ca9a1baf02ad..e7aac5162a257 100644 --- a/models/gpg_key.go +++ b/models/gpg_key.go @@ -20,8 +20,8 @@ import ( type GPGKey struct { ID int64 `xorm:"pk autoincr"` OwnerID int64 `xorm:"INDEX NOT NULL"` - KeyID string `xorm:"INDEX TEXT NOT NULL"` - PrimaryKeyID string `xorm:"TEXT"` + KeyID string `xorm:"INDEX CHAR(16) NOT NULL"` + PrimaryKeyID string `xorm:"CHAR(16)"` Content string `xorm:"TEXT NOT NULL"` Created time.Time `xorm:"-"` CreatedUnix int64 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 4f1254b9605d1..d06a4473b8343 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -96,6 +96,8 @@ var migrations = []Migration{ NewMigration("generate and migrate wiki Git hooks", generateAndMigrateWikiGitHooks), // v23 -> v24 NewMigration("add user openid table", addUserOpenID), + // v24 -> v25 + NewMigration("change the key_id and primary_key_id type", changeGPGKeysColumns), } // Migrate database to current version diff --git a/models/migrations/v24.go b/models/migrations/v24.go new file mode 100644 index 0000000000000..076c710cc33a8 --- /dev/null +++ b/models/migrations/v24.go @@ -0,0 +1,50 @@ +// Copyright 2017 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 ( + "time" + + "github.com/go-xorm/xorm" +) + +func changeGPGKeysColumns(x *xorm.Engine) error { + // EmailAddress is the list of all email addresses of a user. Can contain the + // primary email address, but is not obligatory. + type EmailAddress struct { + ID int64 `xorm:"pk autoincr"` + UID int64 `xorm:"INDEX NOT NULL"` + Email string `xorm:"UNIQUE NOT NULL"` + IsActivated bool + IsPrimary bool `xorm:"-"` + } + + // GPGKey represents a GPG key. + type GPGKey struct { + ID int64 `xorm:"pk autoincr"` + OwnerID int64 `xorm:"INDEX NOT NULL"` + KeyID string `xorm:"INDEX CHAR(16) NOT NULL"` + PrimaryKeyID string `xorm:"CHAR(16)"` + Content string `xorm:"TEXT NOT NULL"` + Created time.Time `xorm:"-"` + CreatedUnix int64 + Expired time.Time `xorm:"-"` + ExpiredUnix int64 + Added time.Time `xorm:"-"` + AddedUnix int64 + SubsKey []*GPGKey `xorm:"-"` + Emails []*EmailAddress + CanSign bool + CanEncryptComms bool + CanEncryptStorage bool + CanCertify bool + } + + if err := x.DropTables(new(GPGKey)); err != nil { + return err + } + + return x.Sync(new(GPGKey)) +}