graphql-engine/cli/commands/metadata_clear.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.5 KiB
Go
Raw Normal View History

2018-06-24 16:40:48 +03:00
package commands
import (
"github.com/hasura/graphql-engine/cli/v2"
"github.com/hasura/graphql-engine/cli/v2/internal/projectmetadata"
2018-06-24 16:40:48 +03:00
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func newMetadataClearCmd(ec *cli.ExecutionContext) *cobra.Command {
opts := &MetadataClearOptions{
EC: ec,
2018-06-24 16:40:48 +03:00
}
metadataResetCmd := &cobra.Command{
Use: "clear",
Aliases: []string{"reset"},
Short: "Clear Hasura GraphQL engine metadata on the database",
Example: ` # Clear all the metadata information from database:
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 {
if cmd.CalledAs() == "reset" {
opts.EC.Logger.Warn("metadata reset command is deprecated, use metadata clear instead")
}
opts.EC.Spin("Clearing metadata...")
err := opts.Run()
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
}
type MetadataClearOptions struct {
2018-06-24 16:40:48 +03:00
EC *cli.ExecutionContext
}
func (o *MetadataClearOptions) Run() error {
var err error
metadataHandler := projectmetadata.NewHandlerFromEC(o.EC)
err = metadataHandler.ResetMetadata()
2018-06-24 16:40:48 +03:00
if err != nil {
return errors.Wrap(err, "cannot clear Metadata")
2018-06-24 16:40:48 +03:00
}
return nil
}