2019-12-25 11:33:06 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2022-11-08 16:04:14 +03:00
|
|
|
"fmt"
|
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
2022-11-08 16:04:14 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
|
2021-07-23 12:49:44 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/projectmetadata"
|
|
|
|
|
2019-12-25 11:33:06 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newMetadataInconsistencyDropCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
|
|
opts := &metadataInconsistencyDropOptions{
|
|
|
|
EC: ec,
|
|
|
|
}
|
|
|
|
metadataInconsistencyDropCmd := &cobra.Command{
|
2023-01-09 07:25:53 +03:00
|
|
|
Use: "drop",
|
|
|
|
Short: "Drop inconsistent objects from the Hasura Metadata",
|
|
|
|
Long: `At times, when developing, the Hasura Metadata can become inconsistent. This command can be used to drop inconsistent objects from the Hasura Metadata and bring your project's Metadata back to a consistent state.
|
|
|
|
|
|
|
|
Further reading:
|
|
|
|
- https://hasura.io/docs/latest/migrations-metadata-seeds/resetting-migrations-metadata/
|
|
|
|
`,
|
2019-12-25 11:33:06 +03:00
|
|
|
SilenceUsage: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-11-08 16:04:14 +03:00
|
|
|
op := genOpName(cmd, "RunE")
|
2019-12-25 11:33:06 +03:00
|
|
|
opts.EC.Spin("Dropping inconsistent metadata...")
|
|
|
|
err := opts.run()
|
|
|
|
opts.EC.Spinner.Stop()
|
|
|
|
if err != nil {
|
2022-11-08 16:04:14 +03:00
|
|
|
return errors.E(op, fmt.Errorf("failed to drop inconsistent metadata: %w", err))
|
2019-12-25 11:33:06 +03:00
|
|
|
}
|
|
|
|
opts.EC.Logger.Info("all inconsistent objects removed from metadata")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return metadataInconsistencyDropCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type metadataInconsistencyDropOptions struct {
|
|
|
|
EC *cli.ExecutionContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *metadataInconsistencyDropOptions) run() error {
|
2022-11-08 16:04:14 +03:00
|
|
|
var op errors.Op = "commands.metadataInconsistencyDropOptions.run"
|
|
|
|
if err := projectmetadata.NewHandlerFromEC(o.EC).DropInconsistentMetadata(); err != nil {
|
|
|
|
return errors.E(op, err)
|
|
|
|
}
|
|
|
|
return nil
|
2019-12-25 11:33:06 +03:00
|
|
|
}
|