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

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