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

v165.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_14 //nolint
  4. import (
  5. "code.gitea.io/gitea/models/migrations/base"
  6. "xorm.io/xorm"
  7. "xorm.io/xorm/schemas"
  8. )
  9. func ConvertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error {
  10. dbType := x.Dialect().URI().DBType
  11. if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
  12. return nil
  13. }
  14. type HookTask struct { //nolint:unused
  15. Typ string `xorm:"VARCHAR(16) index"`
  16. }
  17. if err := base.ModifyColumn(x, "hook_task", &schemas.Column{
  18. Name: "typ",
  19. SQLType: schemas.SQLType{
  20. Name: "VARCHAR",
  21. },
  22. Length: 16,
  23. Nullable: true, // To keep compatible as nullable
  24. DefaultIsEmpty: true,
  25. }); err != nil {
  26. return err
  27. }
  28. var hookTaskTrimSQL string
  29. if dbType == schemas.MSSQL {
  30. hookTaskTrimSQL = "UPDATE hook_task SET typ = RTRIM(LTRIM(typ))"
  31. } else {
  32. hookTaskTrimSQL = "UPDATE hook_task SET typ = TRIM(typ)"
  33. }
  34. if _, err := x.Exec(hookTaskTrimSQL); err != nil {
  35. return err
  36. }
  37. type Webhook struct { //nolint:unused
  38. Type string `xorm:"VARCHAR(16) index"`
  39. }
  40. if err := base.ModifyColumn(x, "webhook", &schemas.Column{
  41. Name: "type",
  42. SQLType: schemas.SQLType{
  43. Name: "VARCHAR",
  44. },
  45. Length: 16,
  46. Nullable: true, // To keep compatible as nullable
  47. DefaultIsEmpty: true,
  48. }); err != nil {
  49. return err
  50. }
  51. var webhookTrimSQL string
  52. if dbType == schemas.MSSQL {
  53. webhookTrimSQL = "UPDATE webhook SET type = RTRIM(LTRIM(type))"
  54. } else {
  55. webhookTrimSQL = "UPDATE webhook SET type = TRIM(type)"
  56. }
  57. _, err := x.Exec(webhookTrimSQL)
  58. return err
  59. }