mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
bb63d7e60e
Co-authored-by: Rishichandra Wawhal <rishichandra.wawhal@gmail.com> Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Co-authored-by: Aravind <aravindkp@outlook.in> Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com> Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package commands
|
|
|
|
import (
|
|
"github.com/hasura/graphql-engine/cli"
|
|
"github.com/pkg/errors"
|
|
"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{
|
|
EC: ec,
|
|
ActionType: "export",
|
|
}
|
|
|
|
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>"`,
|
|
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
|
|
},
|
|
Long: longHelpMetadataExportCmd,
|
|
}
|
|
|
|
return metadataExportCmd
|
|
}
|
|
|
|
type MetadataExportOptions struct {
|
|
EC *cli.ExecutionContext
|
|
|
|
ActionType string
|
|
}
|
|
|
|
func (o *MetadataExportOptions) Run() error {
|
|
migrateDrv, err := newMigrate(o.EC, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return executeMetadata(o.ActionType, migrateDrv, o.EC)
|
|
}
|