v1.3.4.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package migrationnotes
  2. import (
  3. "fmt"
  4. "os"
  5. "strings"
  6. )
  7. func migrateBefore1_3_4(dir, style string) error {
  8. ok, err := needShow1_3_4(dir, style)
  9. if err != nil {
  10. return err
  11. }
  12. if !ok {
  13. return nil
  14. }
  15. fmt.Println(`It seems like that your goctlwt has just been upgraded to version 1.3.4 or later, which refactored the code of the model module. The original XXXmodel.go has been split into XXXmodel_gen.go (read-only) and XXXmodel.go. You just need to follow these steps to complete the migration:
  16. 1. back up the original XXXmodel.go (make sure the file name is no longer in the current directory)
  17. 2. re-run the generate command (a new XXXmodel.go will be created)
  18. 3. populate XXXmodel.go with the code that is not generated by goctlwt according to the comments in XXXmodel_gen.go`)
  19. return nil
  20. }
  21. func needShow1_3_4(dir, style string) (bool, error) {
  22. files, err := os.ReadDir(dir)
  23. if err != nil {
  24. return false, nil
  25. }
  26. // Returns false when the directory contains a file with the suffix "_gen.go"
  27. // In addition, it returns true if it contains a model file extension.
  28. // In other case, false is returned.
  29. for _, f := range files {
  30. if f.IsDir() {
  31. continue
  32. }
  33. if strings.HasSuffix(f.Name(), "_gen.go") {
  34. return false, nil
  35. }
  36. }
  37. modelSuffix, err := getModelSuffix(style)
  38. if err != nil {
  39. return false, err
  40. }
  41. for _, f := range files {
  42. if !f.IsDir() && strings.HasSuffix(f.Name(), modelSuffix) {
  43. return true, nil
  44. }
  45. }
  46. return false, nil
  47. }