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.3 kB

3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. {"Custom v1 Topic struct change to support chinese", syncTopicStruct},
  16. }
  17. var customMigrationsStatic = []CustomMigrationStatic{
  18. {"update issue_fixed_rate to 1 if num_issues is 0 ", updateIssueFixedRate},
  19. }
  20. func MigrateCustom(x *xorm.Engine) {
  21. for _, m := range customMigrations {
  22. log.Info("Migration: %s", m.Description)
  23. if err := m.Migrate(x); err != nil {
  24. log.Error("Migration: %v", err)
  25. }
  26. }
  27. }
  28. func MigrateCustomStatic(x *xorm.Engine, static *xorm.Engine) {
  29. for _, m := range customMigrationsStatic {
  30. log.Info("Migration: %s", m.Description)
  31. if err := m.Migrate(x, static); err != nil {
  32. log.Error("Migration: %v", err)
  33. }
  34. }
  35. }
  36. func syncTopicStruct(x *xorm.Engine) error {
  37. query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);"
  38. _, err := x.Exec(query)
  39. return err
  40. }
  41. func updateIssueFixedRate(x *xorm.Engine, static *xorm.Engine) error {
  42. updateSQL := "update repo_statistic set issue_fixed_rate=1.0 where num_issues=0"
  43. _, err := static.Exec(updateSQL)
  44. return err
  45. }