summaryrefslogtreecommitdiffstats
path: root/models/migrations/v150.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-09-10 20:45:01 +0100
committerGitHub <noreply@github.com>2020-09-10 20:45:01 +0100
commit47289344e2ede03b7a74208aad3b92c8bca979c3 (patch)
treee1920df9ef18854585ed08136249ad185bc1cf96 /models/migrations/v150.go
parent4f8dad37f834833012004bf5b158e5129af4b610 (diff)
downloadgitea-47289344e2ede03b7a74208aad3b92c8bca979c3.tar.gz
gitea-47289344e2ede03b7a74208aad3b92c8bca979c3.zip
Add Primary Key to Topic and RepoTopic (#12639)
Add a primary key to Topic and RepoTopic tables Fix #8920 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models/migrations/v150.go')
-rw-r--r--models/migrations/v150.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/models/migrations/v150.go b/models/migrations/v150.go
new file mode 100644
index 0000000000..41d6a90401
--- /dev/null
+++ b/models/migrations/v150.go
@@ -0,0 +1,39 @@
+// Copyright 2020 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 (
+ "code.gitea.io/gitea/modules/timeutil"
+
+ "xorm.io/xorm"
+)
+
+func addPrimaryKeyToRepoTopic(x *xorm.Engine) error {
+ // Topic represents a topic of repositories
+ type Topic struct {
+ ID int64 `xorm:"pk autoincr"`
+ Name string `xorm:"UNIQUE VARCHAR(25)"`
+ RepoCount int
+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
+ UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
+ }
+
+ // RepoTopic represents associated repositories and topics
+ type RepoTopic struct {
+ RepoID int64 `xorm:"pk"`
+ TopicID int64 `xorm:"pk"`
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ recreateTable(sess, &Topic{})
+ recreateTable(sess, &RepoTopic{})
+
+ return sess.Commit()
+}