File tree 3 files changed +44
-3
lines changed
3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,8 @@ var migrations = []Migration{
233
233
NewMigration ("remove issue dependency comments who refer to non existing issues" , purgeInvalidDependenciesComments ),
234
234
// v149 -> v150
235
235
NewMigration ("Add Created and Updated to Milestone table" , addCreatedAndUpdatedToMilestones ),
236
+ // v150 -> v151
237
+ NewMigration ("add primary key to repo_topic" , addPrimaryKeyToRepoTopic ),
236
238
}
237
239
238
240
// GetCurrentDBVersion returns the current db version
Original file line number Diff line number Diff line change
1
+ // Copyright 2020 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/timeutil"
9
+
10
+ "xorm.io/xorm"
11
+ )
12
+
13
+ func addPrimaryKeyToRepoTopic (x * xorm.Engine ) error {
14
+ // Topic represents a topic of repositories
15
+ type Topic struct {
16
+ ID int64 `xorm:"pk autoincr"`
17
+ Name string `xorm:"UNIQUE VARCHAR(25)"`
18
+ RepoCount int
19
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
20
+ UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
21
+ }
22
+
23
+ // RepoTopic represents associated repositories and topics
24
+ type RepoTopic struct {
25
+ RepoID int64 `xorm:"pk"`
26
+ TopicID int64 `xorm:"pk"`
27
+ }
28
+
29
+ sess := x .NewSession ()
30
+ defer sess .Close ()
31
+ if err := sess .Begin (); err != nil {
32
+ return err
33
+ }
34
+
35
+ recreateTable (sess , & Topic {})
36
+ recreateTable (sess , & RepoTopic {})
37
+
38
+ return sess .Commit ()
39
+ }
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
25
25
26
26
// Topic represents a topic of repositories
27
27
type Topic struct {
28
- ID int64
28
+ ID int64 `xorm:"pk autoincr"`
29
29
Name string `xorm:"UNIQUE VARCHAR(25)"`
30
30
RepoCount int
31
31
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
@@ -34,8 +34,8 @@ type Topic struct {
34
34
35
35
// RepoTopic represents associated repositories and topics
36
36
type RepoTopic struct {
37
- RepoID int64 `xorm:"UNIQUE(s) "`
38
- TopicID int64 `xorm:"UNIQUE(s) "`
37
+ RepoID int64 `xorm:"pk "`
38
+ TopicID int64 `xorm:"pk "`
39
39
}
40
40
41
41
// ErrTopicNotExist represents an error that a topic is not exist
You can’t perform that action at this time.
0 commit comments