gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_13
  4. import (
  5. "code.gitea.io/gitea/models/migrations/base"
  6. "code.gitea.io/gitea/modules/timeutil"
  7. "xorm.io/xorm"
  8. )
  9. func AddPrimaryKeyToRepoTopic(x *xorm.Engine) error {
  10. // Topic represents a topic of repositories
  11. type Topic struct {
  12. ID int64 `xorm:"pk autoincr"`
  13. Name string `xorm:"UNIQUE VARCHAR(25)"`
  14. RepoCount int
  15. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  16. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  17. }
  18. // RepoTopic represents associated repositories and topics
  19. type RepoTopic struct {
  20. RepoID int64 `xorm:"pk"`
  21. TopicID int64 `xorm:"pk"`
  22. }
  23. sess := x.NewSession()
  24. defer sess.Close()
  25. if err := sess.Begin(); err != nil {
  26. return err
  27. }
  28. base.RecreateTable(sess, &Topic{})
  29. base.RecreateTable(sess, &RepoTopic{})
  30. return sess.Commit()
  31. }