graphql-engine/cli/commands/metadata_export.go

64 lines
1.8 KiB
Go
Raw Normal View History

2018-06-24 16:40:48 +03:00
package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/hasura/graphql-engine/cli/internal/hasura"
2020-04-07 12:23:20 +03:00
"github.com/hasura/graphql-engine/cli/migrate"
"github.com/pkg/errors"
2018-06-24 16:40:48 +03:00
"github.com/spf13/cobra"
)
const longHelpMetadataExportCmd = `Export Hasura metadata and save it in migrations/metadata.yaml file.
The output is a yaml file which captures all the metadata required
by GraphQL Engine. This includes info about tables that are tracked,
permission rules, relationships and event triggers that are defined
on those tables.`
func newMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
opts := &MetadataExportOptions{
2018-06-24 16:40:48 +03:00
EC: ec,
ActionType: "export",
2018-06-24 16:40:48 +03:00
}
metadataExportCmd := &cobra.Command{
Use: "export",
Short: "Export Hasura GraphQL Engine metadata from the database",
Example: ` # Export metadata and save it in migrations/metadata.yaml file:
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 {
opts.EC.Spin("Exporting metadata...")
err := opts.Run()
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
},
Long: longHelpMetadataExportCmd,
2018-06-24 16:40:48 +03:00
}
return metadataExportCmd
}
type MetadataExportOptions struct {
2018-06-24 16:40:48 +03:00
EC *cli.ExecutionContext
ActionType string
2018-06-24 16:40:48 +03:00
}
func (o *MetadataExportOptions) Run() error {
migrateDrv, err := migrate.NewMigrate(o.EC, true, "", hasura.SourceKindPG)
2018-06-24 16:40:48 +03:00
if err != nil {
return err
2018-06-24 16:40:48 +03:00
}
return executeMetadata(o.ActionType, migrateDrv, o.EC)
2018-06-24 16:40:48 +03:00
}