Repository: hasura/graphql-engine
File: cli/commands/migrate_squash.go (Go)

Code before:

	mig "github.com/hasura/graphql-engine/cli/migrate/cmd"
)

func newMigrateSquashCmd(ec *cli.ExecutionContext) *cobra.Command {
	v := viper.New()
	opts := &migrateSquashOptions{
		EC: ec,
	}
	migrateSquashCmd := &cobra.Command{
		Use:   "squash",
		Short: "(PREVIEW) Squash multiple migrations into a single one",
		Long:  "(PREVIEW) Squash multiple migrations leading upto the latest one into a single migration file",
		Example: `  # NOTE: This command is in PREVIEW, correctness is not guaranteed and the usage may change.

  # squash all migrations from version 123 to the latest one:
  hasura migrate squash --from 123

	# Add admin secret for Hasura GraphQL Engine:
	hasura migrate squash --admin-secret "<admin-secret>"

	# Add Hasura GraphQL Server endpoint:
	hasura migrate squash --endpoint "<http-endpoint>"

	# Add a name for the new squashed migration
	hasura migrate squash --name "<name>"`,
		SilenceUsage: true,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			ec.Viper = v
			return ec.Validate()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.newVersion = getTime()
			return opts.run()
		},
	}

	f := migrateSquashCmd.Flags()
	f.Uint64Var(&opts.from, "from", 0, "start squashing form this version")
	f.StringVar(&opts.name, "name", "squashed", "name for the new squashed migration")
	f.BoolVar(&opts.deleteSource, "delete-source", false, "delete the source files after squashing without any confirmation")

	f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")
	f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine")
	f.String("access-key", "", "access key for Hasura GraphQL Engine")
	f.MarkDeprecated("access-key", "use --admin-secret instead")

	// need to create a new viper because https://github.com/spf13/viper/issues/233
	v.BindPFlag("endpoint", f.Lookup("endpoint"))
	v.BindPFlag("admin_secret", f.Lookup("admin-secret"))
	v.BindPFlag("access_key", f.Lookup("access-key"))

Review comment (suggestion):
```suggestion
	hasura migrate squash --name "<name>" --from 123`,
```

Code after:

	mig "github.com/hasura/graphql-engine/cli/migrate/cmd"
)

func newMigrateSquashCmd(ec *cli.ExecutionContext) *cobra.Command {
	v := viper.New()
	opts := &migrateSquashOptions{
		EC: ec,
	}
	migrateSquashCmd := &cobra.Command{
		Use:   "squash",
		Short: "(PREVIEW) Squash multiple migrations into a single one",
		Long:  "(PREVIEW) Squash multiple migrations leading upto the latest one into a single migration file",
		Example: `  # NOTE: This command is in PREVIEW, correctness is not guaranteed and the usage may change.

  # squash all migrations from version 123 to the latest one:
  hasura migrate squash --from 123

  # Add a name for the new squashed migration
  hasura migrate squash --name "<name>" --from 123`,
		SilenceUsage: true,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			ec.Viper = v
			return ec.Validate()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.newVersion = getTime()
			return opts.run()
		},
	}

	f := migrateSquashCmd.Flags()
	f.Uint64Var(&opts.from, "from", 0, "start squashing form this version")
	f.StringVar(&opts.name, "name", "squashed", "name for the new squashed migration")
	f.BoolVar(&opts.deleteSource, "delete-source", false, "delete the source files after squashing without any confirmation")

	f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")
	f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine")
	f.String("access-key", "", "access key for Hasura GraphQL Engine")
	f.MarkDeprecated("access-key", "use --admin-secret instead")

	// need to create a new viper because https://github.com/spf13/viper/issues/233
	v.BindPFlag("endpoint", f.Lookup("endpoint"))
	v.BindPFlag("admin_secret", f.Lookup("admin-secret"))
	v.BindPFlag("access_key", f.Lookup("access-key"))

	return migrateSquashCmd
}

type migrateSquashOptions struct {
	EC *cli.ExecutionContext