2018-06-24 16:40:48 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2019-03-29 08:14:56 +03:00
|
|
|
func newMetadataClearCmd(ec *cli.ExecutionContext) *cobra.Command {
|
2020-02-24 19:14:46 +03:00
|
|
|
opts := &MetadataClearOptions{
|
2018-06-24 16:40:48 +03:00
|
|
|
EC: ec,
|
2020-02-24 19:14:46 +03:00
|
|
|
ActionType: "clear",
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
metadataResetCmd := &cobra.Command{
|
2019-03-29 08:14:56 +03:00
|
|
|
Use: "clear",
|
|
|
|
Aliases: []string{"reset"},
|
2021-03-15 18:40:52 +03:00
|
|
|
Short: "Clear Hasura GraphQL engine metadata on the database",
|
2019-03-29 08:14:56 +03:00
|
|
|
Example: ` # Clear all the metadata information from database:
|
2019-12-12 08:16:36 +03:00
|
|
|
hasura metadata clear
|
|
|
|
|
|
|
|
# Use with admin secret:
|
|
|
|
hasura metadata clear --admin-secret "<admin-secret>"
|
|
|
|
|
|
|
|
# Clear metadata on a different Hasura instance:
|
|
|
|
hasura metadata clear --endpoint "<endpoint>"`,
|
2018-06-24 16:40:48 +03:00
|
|
|
SilenceUsage: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-03-29 08:14:56 +03:00
|
|
|
if cmd.CalledAs() == "reset" {
|
|
|
|
opts.EC.Logger.Warn("metadata reset command is deprecated, use metadata clear instead")
|
|
|
|
}
|
2019-04-03 08:52:03 +03:00
|
|
|
opts.EC.Spin("Clearing metadata...")
|
2020-02-24 19:14:46 +03:00
|
|
|
err := opts.Run()
|
2019-04-03 08:52:03 +03:00
|
|
|
opts.EC.Spinner.Stop()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to clear metadata")
|
|
|
|
}
|
|
|
|
opts.EC.Logger.Info("Metadata cleared")
|
|
|
|
return nil
|
2018-06-24 16:40:48 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return metadataResetCmd
|
|
|
|
}
|
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
type MetadataClearOptions struct {
|
2018-06-24 16:40:48 +03:00
|
|
|
EC *cli.ExecutionContext
|
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
ActionType string
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
func (o *MetadataClearOptions) Run() error {
|
2021-04-01 08:13:24 +03:00
|
|
|
err := executeMetadata(o.ActionType, o.EC)
|
2018-06-24 16:40:48 +03:00
|
|
|
if err != nil {
|
2019-03-29 08:14:56 +03:00
|
|
|
return errors.Wrap(err, "Cannot clear metadata")
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|