2018-06-24 16:40:48 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
2019-04-03 08:52:03 +03:00
|
|
|
"github.com/pkg/errors"
|
2018-06-24 16:40:48 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2021-03-15 18:40:52 +03:00
|
|
|
const longHelpMetadataExportCmd = `Export Hasura metadata and save it in the` + " ``/metadata``" + ` directory.
|
|
|
|
The output is a bunch of yaml files which captures all the metadata required
|
|
|
|
by the GraphQL engine. This includes info about tables that are tracked,
|
2019-02-14 12:37:47 +03:00
|
|
|
permission rules, relationships and event triggers that are defined
|
2021-03-15 18:40:52 +03:00
|
|
|
on those tables`
|
2018-10-08 10:24:43 +03:00
|
|
|
|
2018-06-28 11:36:25 +03:00
|
|
|
func newMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
|
2020-02-24 19:14:46 +03:00
|
|
|
opts := &MetadataExportOptions{
|
2018-06-24 16:40:48 +03:00
|
|
|
EC: ec,
|
2020-02-24 19:14:46 +03:00
|
|
|
ActionType: "export",
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
metadataExportCmd := &cobra.Command{
|
|
|
|
Use: "export",
|
2021-03-15 18:40:52 +03:00
|
|
|
Short: "Export Hasura GraphQL engine metadata from the database",
|
2018-10-08 10:24:43 +03:00
|
|
|
Example: ` # Export metadata and save it in migrations/metadata.yaml file:
|
2019-12-12 08:16:36 +03:00
|
|
|
hasura metadata export
|
|
|
|
|
|
|
|
# Use with admin secret:
|
|
|
|
hasura metadata export --admin-secret "<admin-secret>"
|
|
|
|
|
|
|
|
# Export metadata to another instance specified by the flag:
|
|
|
|
hasura metadata export --endpoint "<endpoint>"`,
|
2018-06-24 16:40:48 +03:00
|
|
|
SilenceUsage: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2019-04-03 08:52:03 +03:00
|
|
|
opts.EC.Spin("Exporting 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 export metadata")
|
|
|
|
}
|
|
|
|
opts.EC.Logger.Info("Metadata exported")
|
|
|
|
return nil
|
2018-06-24 16:40:48 +03:00
|
|
|
},
|
2018-10-08 10:24:43 +03:00
|
|
|
Long: longHelpMetadataExportCmd,
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return metadataExportCmd
|
|
|
|
}
|
|
|
|
|
2020-02-24 19:14:46 +03:00
|
|
|
type MetadataExportOptions 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 *MetadataExportOptions) Run() error {
|
2021-04-01 08:13:24 +03:00
|
|
|
return executeMetadata(o.ActionType, o.EC)
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|