migrate.go 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "errors"
  4. "strconv"
  5. _ "code.osinet.fr/fgm/kurz/migrations"
  6. "github.com/spf13/cobra"
  7. )
  8. var cmdMigrate = &cobra.Command{
  9. Args: cobra.NoArgs,
  10. Long: "Custom Kurz version of Goose CLI",
  11. Short: "Top-level command for migrations. Kurz version of 'goose', without the 'create' subcommand.",
  12. Use: "migrate",
  13. }
  14. // Used by the down-to and up-to commands.
  15. var migrateTargetVersion int64 = 0
  16. func init() {
  17. cmd.AddCommand(cmdMigrate)
  18. }
  19. func migrateVersionValidator(cmd *cobra.Command, args []string) error {
  20. if len(args) != 1 {
  21. return errors.New(cmd.Name() + " only accepts a single numeric version parameter")
  22. }
  23. // Arguments count was validated by cmdMigrate.Args: ExactArgs(1).
  24. target, err := strconv.ParseInt(args[0], 10, 64)
  25. if err != nil {
  26. return errors.New(cmd.Name() + " could not parse target version number")
  27. }
  28. if target < 0 {
  29. return errors.New(cmd.Name() + " version numbers must be positive")
  30. }
  31. migrateTargetVersion = target
  32. return nil
  33. }