2018-06-24 16:40:48 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-06-28 11:36:25 +03:00
|
|
|
func newMetadataApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
|
2018-06-24 16:40:48 +03:00
|
|
|
opts := &metadataApplyOptions{
|
|
|
|
EC: ec,
|
|
|
|
actionType: "apply",
|
|
|
|
}
|
|
|
|
|
|
|
|
metadataApplyCmd := &cobra.Command{
|
|
|
|
Use: "apply",
|
|
|
|
Short: "Apply Hasura metadata on a database",
|
|
|
|
Example: ` # Apply Hasura GraphQL Engine metadata present in metadata.yaml file:
|
|
|
|
hasura metadata apply`,
|
|
|
|
SilenceUsage: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-06-28 11:36:25 +03:00
|
|
|
return opts.run()
|
2018-06-24 16:40:48 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return metadataApplyCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type metadataApplyOptions struct {
|
|
|
|
EC *cli.ExecutionContext
|
|
|
|
|
|
|
|
actionType string
|
|
|
|
}
|
|
|
|
|
2018-06-28 11:36:25 +03:00
|
|
|
func (o *metadataApplyOptions) run() error {
|
2018-07-09 16:47:38 +03:00
|
|
|
migrateDrv, err := newMigrate(o.EC.MigrationDir, o.EC.Config.ParsedEndpoint, o.EC.Config.AccessKey, o.EC.Logger)
|
2018-06-24 16:40:48 +03:00
|
|
|
if err != nil {
|
2018-07-09 16:47:38 +03:00
|
|
|
return err
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|
2018-07-09 16:47:38 +03:00
|
|
|
return executeMetadata(o.actionType, migrateDrv, o.EC.ExecutionDirectory)
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|