2018-10-16 09:25:30 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
2021-07-23 12:49:44 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/projectmetadata"
|
|
|
|
|
2018-10-16 09:25:30 +03:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newMetadataReloadCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
|
|
opts := &metadataReloadOptions{
|
2021-05-14 22:09:01 +03:00
|
|
|
EC: ec,
|
2018-10-16 09:25:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
metadataReloadCmd := &cobra.Command{
|
|
|
|
Use: "reload",
|
2021-03-15 18:40:52 +03:00
|
|
|
Short: "Reload Hasura GraphQL engine metadata on the database",
|
2018-10-16 09:25:30 +03:00
|
|
|
Example: ` # Reload all the metadata information from database:
|
2019-12-12 08:16:36 +03:00
|
|
|
hasura metadata reload
|
|
|
|
|
|
|
|
# Use with admin secret:
|
|
|
|
hasura metadata reload --admin-secret "<admin-secret>"
|
|
|
|
|
|
|
|
# Reload metadata on a different instance:
|
|
|
|
hasura metadata export --endpoint "<endpoint>"`,
|
2018-10-16 09:25:30 +03:00
|
|
|
SilenceUsage: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-04-03 08:52:03 +03:00
|
|
|
opts.EC.Spin("Reloading metadata...")
|
|
|
|
err := opts.run()
|
|
|
|
opts.EC.Spinner.Stop()
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to reload metadata")
|
|
|
|
}
|
|
|
|
opts.EC.Logger.Info("Metadata reloaded")
|
|
|
|
return nil
|
2018-10-16 09:25:30 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return metadataReloadCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type metadataReloadOptions struct {
|
|
|
|
EC *cli.ExecutionContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *metadataReloadOptions) run() error {
|
2021-05-14 22:09:01 +03:00
|
|
|
|
|
|
|
var err error
|
2021-07-23 12:49:44 +03:00
|
|
|
metadataHandler := projectmetadata.NewHandlerFromEC(ec)
|
2021-06-18 09:24:16 +03:00
|
|
|
_, err = metadataHandler.ReloadMetadata()
|
2018-10-16 09:25:30 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Cannot reload metadata")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|