2018-10-16 09:25:30 +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-10-16 09:25:30 +03:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newMetadataReloadCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
|
|
opts := &metadataReloadOptions{
|
|
|
|
EC: ec,
|
|
|
|
actionType: "reload",
|
|
|
|
}
|
|
|
|
|
|
|
|
metadataReloadCmd := &cobra.Command{
|
|
|
|
Use: "reload",
|
|
|
|
Short: "Reload Hasura GraphQL Engine metadata on the database",
|
|
|
|
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
|
|
|
|
|
|
|
|
actionType string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *metadataReloadOptions) run() error {
|
2020-04-07 12:23:20 +03:00
|
|
|
migrateDrv, err := migrate.NewMigrate(o.EC, true)
|
2018-10-16 09:25:30 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-03-20 08:10:06 +03:00
|
|
|
err = executeMetadata(o.actionType, migrateDrv, o.EC)
|
2018-10-16 09:25:30 +03:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "Cannot reload metadata")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|