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 912 B

4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. var customMigrations = []CustomMigration{
  11. {"Custom v1 Topic struct change to support chinese", syncTopicStruct},
  12. }
  13. var customMigrationsStatic = []CustomMigration{}
  14. func MigrateCustom(x *xorm.Engine) {
  15. for _, m := range customMigrations {
  16. log.Info("Migration: %s", m.Description)
  17. if err := m.Migrate(x); err != nil {
  18. log.Error("Migration: %v", err)
  19. }
  20. }
  21. }
  22. func MigrateCustomStatic(x *xorm.Engine) {
  23. for _, m := range customMigrationsStatic {
  24. log.Info("Migration: %s", m.Description)
  25. if err := m.Migrate(x); err != nil {
  26. log.Error("Migration: %v", err)
  27. }
  28. }
  29. }
  30. func syncTopicStruct(x *xorm.Engine) error {
  31. query := "ALTER TABLE topic ALTER COLUMN name TYPE varchar(105);"
  32. _, err := x.Exec(query)
  33. return err
  34. }