2018-06-24 16:40:48 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
2020-04-07 12:23:20 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/migrate"
|
2018-06-24 16:40:48 +03:00
|
|
|
"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"},
|
|
|
|
Short: "Clear Hasura GraphQL Engine metadata on the database",
|
|
|
|
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 {
|
2020-04-07 12:23:20 +03:00
|
|
|
migrateDrv, err := migrate.NewMigrate(o.EC, true)
|
2018-06-24 16:40:48 +03:00
|
|
|
if err != nil {
|
2018-07-09 16:47:38 +03:00
|
|
|
return err
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
2020-02-24 19:14:46 +03:00
|
|
|
err = executeMetadata(o.ActionType, migrateDrv, 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
|
|
|
|
}
|