summaryrefslogtreecommitdiffstats
path: root/models/forgejo_migrations/v20.go
blob: 8ca9e91f7309bd92d7750406da3ebada3fc3e682 (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
51
52
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package forgejo_migrations //nolint:revive

import "xorm.io/xorm"

type (
	QuotaLimitSubject  int
	QuotaLimitSubjects []QuotaLimitSubject

	QuotaKind int
)

type QuotaRule struct {
	Name     string `xorm:"pk not null"`
	Limit    int64  `xorm:"NOT NULL"`
	Subjects QuotaLimitSubjects
}

type QuotaGroup struct {
	Name string `xorm:"pk NOT NULL"`
}

type QuotaGroupRuleMapping struct {
	ID        int64  `xorm:"pk autoincr"`
	GroupName string `xorm:"index unique(qgrm_gr) not null"`
	RuleName  string `xorm:"unique(qgrm_gr) not null"`
}

type QuotaGroupMapping struct {
	ID        int64     `xorm:"pk autoincr"`
	Kind      QuotaKind `xorm:"unique(qgm_kmg) not null"`
	MappedID  int64     `xorm:"unique(qgm_kmg) not null"`
	GroupName string    `xorm:"index unique(qgm_kmg) not null"`
}

func CreateQuotaTables(x *xorm.Engine) error {
	if err := x.Sync(new(QuotaRule)); err != nil {
		return err
	}

	if err := x.Sync(new(QuotaGroup)); err != nil {
		return err
	}

	if err := x.Sync(new(QuotaGroupRuleMapping)); err != nil {
		return err
	}

	return x.Sync(new(QuotaGroupMapping))
}