2021-01-18 20:11:05 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-05-17 18:19:15 +03:00
|
|
|
"fmt"
|
2021-06-09 10:12:56 +03:00
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/scripts"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2/util"
|
2021-01-18 20:11:05 +03:00
|
|
|
"github.com/spf13/afero"
|
|
|
|
|
2021-06-16 14:44:15 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
2021-01-18 20:11:05 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newUpdateMultipleSources(ec *cli.ExecutionContext) *cobra.Command {
|
|
|
|
v := viper.New()
|
2021-05-17 18:19:15 +03:00
|
|
|
var opts scripts.UpdateProjectV3Opts
|
2021-01-18 20:11:05 +03:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "update-project-v3",
|
2021-03-15 18:40:52 +03:00
|
|
|
Short: "Update the Hasura project from config v2 to v3",
|
2021-01-18 20:11:05 +03:00
|
|
|
Long: `
|
2021-03-08 09:57:50 +03:00
|
|
|
Convenience script used to upgrade your CLI project to use config v3.
|
2021-03-15 18:40:52 +03:00
|
|
|
Note that this process is completely independent from your Hasura Graphql Engine server update process`,
|
2021-01-18 20:11:05 +03:00
|
|
|
SilenceUsage: true,
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
ec.Viper = v
|
|
|
|
err := ec.Prepare()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ec.Validate()
|
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2021-05-17 18:19:15 +03:00
|
|
|
if opts.Force && len(opts.TargetDatabase) == 0 {
|
|
|
|
return fmt.Errorf("--database-name is required when --force is set")
|
2021-01-18 20:11:05 +03:00
|
|
|
}
|
2021-05-17 18:19:15 +03:00
|
|
|
opts.Fs = afero.NewOsFs()
|
|
|
|
opts.ProjectDirectory = ec.ExecutionDirectory
|
|
|
|
opts.MigrationsAbsDirectoryPath = ec.MigrationDir
|
|
|
|
opts.SeedsAbsDirectoryPath = ec.SeedsDirectory
|
|
|
|
opts.Logger = ec.Logger
|
|
|
|
opts.EC = ec
|
2021-02-17 15:51:43 +03:00
|
|
|
return scripts.UpdateProjectV3(opts)
|
2021-01-18 20:11:05 +03:00
|
|
|
},
|
|
|
|
}
|
2021-02-22 15:42:17 +03:00
|
|
|
|
|
|
|
f := cmd.Flags()
|
2021-05-17 18:19:15 +03:00
|
|
|
f.StringVar(&opts.TargetDatabase, "database-name", "", "database name for which the current migrations / seeds belong to")
|
|
|
|
f.BoolVar(&opts.Force, "force", false, "do not ask for confirmation")
|
|
|
|
f.BoolVar(&opts.MoveStateOnly, "move-state-only", false, "do only a state migration from old hdb_catalog.* table to catalog state and skip others")
|
2021-02-22 15:42:17 +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-02-22 15:42:17 +03:00
|
|
|
f.MarkDeprecated("access-key", "use --admin-secret instead")
|
|
|
|
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")
|
|
|
|
|
|
|
|
// need to create a new viper because https://github.com/spf13/viper/issues/233
|
|
|
|
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-01-18 20:11:05 +03:00
|
|
|
return cmd
|
|
|
|
}
|