code.gitea.io/gitea@v1.21.7/models/migrations/v1_13/v150.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package v1_13 //nolint 5 6 import ( 7 "code.gitea.io/gitea/models/migrations/base" 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 base.RecreateTable(sess, &Topic{}) 36 base.RecreateTable(sess, &RepoTopic{}) 37 38 return sess.Commit() 39 }