graphql-engine/cli/commands/metadata_clear.go
Kali Vara Purushotham Santhati c3e60aba28 cli: update cli help texts and docs generation
Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: b6909583093baac4a69296721feae149ca6a0605
2021-03-15 15:41:54 +00:00

65 lines
1.6 KiB
Go

package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/hasura/graphql-engine/cli/internal/hasura"
"github.com/hasura/graphql-engine/cli/migrate"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func newMetadataClearCmd(ec *cli.ExecutionContext) *cobra.Command {
opts := &MetadataClearOptions{
EC: ec,
ActionType: "clear",
}
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>"`,
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
},
}
return metadataResetCmd
}
type MetadataClearOptions struct {
EC *cli.ExecutionContext
ActionType string
}
func (o *MetadataClearOptions) Run() error {
migrateDrv, err := migrate.NewMigrate(o.EC, true, "", hasura.SourceKindPG)
if err != nil {
return err
}
err = executeMetadata(o.ActionType, migrateDrv, o.EC)
if err != nil {
return errors.Wrap(err, "Cannot clear metadata")
}
return nil
}