You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom_migrations.go 1.2 kB

3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "code.gitea.io/gitea/modules/log"
  4. "xorm.io/xorm"
  5. )
  6. type CustomMigration struct {
  7. Description string
  8. Migrate func(*xorm.Engine) error
  9. }
  10. type CustomMigrationStatic struct {
  11. Description string
  12. Migrate func(*xorm.Engine, *xorm.Engine) error
  13. }
  14. var customMigrations []CustomMigration
  15. var customMigrationsStatic []CustomMigrationStatic
  16. func MigrateCustom(x *xorm.Engine) {
  17. for _, m := range customMigrations {
  18. log.Info("Migration: %s", m.Description)
  19. if err := m.Migrate(x); err != nil {
  20. log.Error("Migration: %v", err)
  21. }
  22. }
  23. }
  24. func MigrateCustomStatic(x *xorm.Engine, static *xorm.Engine) {
  25. for _, m := range customMigrationsStatic {
  26. log.Info("Migration: %s", m.Description)
  27. if err := m.Migrate(x, static); err != nil {
  28. log.Error("Migration: %v", err)
  29. }
  30. }
  31. }
  32. func syncTopicStruct(x *xorm.Engine) error {
  33. query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);"
  34. _, err := x.Exec(query)
  35. return err
  36. }
  37. func updateIssueFixedRate(x *xorm.Engine, static *xorm.Engine) error {
  38. updateSQL := "update repo_statistic set issue_fixed_rate=1.0 where num_issues=0"
  39. _, err := static.Exec(updateSQL)
  40. return err
  41. }