2020-06-16 15:15:04 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/seed"
|
2021-04-01 13:38:55 +03:00
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/util"
|
2020-06-16 15:15:04 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewSeedCmd will return the seed command
|
|
|
|
func NewSeedCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
|
|
v := viper.New()
|
|
|
|
ec.Viper = v
|
|
|
|
seedCmd := &cobra.Command{
|
2020-10-07 12:26:30 +03:00
|
|
|
Use: "seed",
|
|
|
|
Aliases: []string{"sd", "seeds"},
|
2020-06-16 15:15:04 +03:00
|
|
|
Short: "Manage seed data",
|
|
|
|
SilenceUsage: true,
|
|
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
err := ec.Prepare()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-18 20:11:05 +03:00
|
|
|
if err := ec.Validate(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2020-06-16 15:15:04 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
seedCmd.AddCommand(
|
|
|
|
newSeedCreateCmd(ec),
|
|
|
|
newSeedApplyCmd(ec),
|
|
|
|
)
|
|
|
|
|
2020-08-18 15:29:58 +03:00
|
|
|
f := seedCmd.PersistentFlags()
|
2021-03-09 09:43:41 +03:00
|
|
|
f.StringVar(&ec.Source.Name, "database-name", "", "database on which operation should be applied")
|
2020-08-18 15:29:58 +03:00
|
|
|
|
2021-03-15 18:40:52 +03:00
|
|
|
f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL engine")
|
|
|
|
f.String("admin-secret", "", "admin secret for Hasura GraphQL engine")
|
|
|
|
f.String("access-key", "", "access key for Hasura GraphQL engine")
|
2021-10-13 17:38:07 +03:00
|
|
|
if err := f.MarkDeprecated("access-key", "use --admin-secret instead"); err != nil {
|
|
|
|
ec.Logger.WithError(err).Errorf("error while using a dependency library")
|
|
|
|
}
|
2020-08-18 15:29:58 +03:00
|
|
|
f.Bool("insecure-skip-tls-verify", false, "skip TLS verification and disable cert checking (default: false)")
|
|
|
|
f.String("certificate-authority", "", "path to a cert file for the certificate authority")
|
2021-06-09 10:12:56 +03:00
|
|
|
f.Bool("disable-interactive", false, "disables interactive prompts (default: false)")
|
2020-08-18 15:29:58 +03:00
|
|
|
|
|
|
|
util.BindPFlag(v, "endpoint", f.Lookup("endpoint"))
|
|
|
|
util.BindPFlag(v, "admin_secret", f.Lookup("admin-secret"))
|
|
|
|
util.BindPFlag(v, "access_key", f.Lookup("access-key"))
|
|
|
|
util.BindPFlag(v, "insecure_skip_tls_verify", f.Lookup("insecure-skip-tls-verify"))
|
|
|
|
util.BindPFlag(v, "certificate_authority", f.Lookup("certificate-authority"))
|
2021-06-09 10:12:56 +03:00
|
|
|
util.BindPFlag(v, "disable_interactive", f.Lookup("disable-interactive"))
|
2020-06-16 15:15:04 +03:00
|
|
|
|
|
|
|
return seedCmd
|
|
|
|
}
|
2021-04-01 13:38:55 +03:00
|
|
|
|
|
|
|
func getSeedDriver(configVersion cli.ConfigVersion) (driver *seed.Driver) {
|
|
|
|
if configVersion >= cli.V3 {
|
|
|
|
driver = seed.NewDriver(ec.APIClient.V2Query.Bulk, ec.APIClient.PGDump)
|
|
|
|
} else {
|
|
|
|
driver = seed.NewDriver(ec.APIClient.V1Query.Bulk, ec.APIClient.PGDump)
|
|
|
|
}
|
|
|
|
return driver
|
|
|
|
}
|