summaryrefslogtreecommitdiffstats
path: root/models/migrations/v24.go
blob: 076c710cc33a84d776bfe624ed02086b6ac7a78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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))
}