2018-06-24 16:40:48 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
|
|
"github.com/hasura/graphql-engine/cli/util"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-06-28 11:36:25 +03:00
|
|
|
func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command {
|
2018-06-24 16:40:48 +03:00
|
|
|
opts := &migrateStatusOptions{
|
|
|
|
EC: ec,
|
|
|
|
}
|
|
|
|
migrateStatusCmd := &cobra.Command{
|
|
|
|
Use: "status",
|
|
|
|
Short: "Display current status of migrations on a database",
|
|
|
|
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 migrateStatusCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
type migrateStatusOptions struct {
|
|
|
|
EC *cli.ExecutionContext
|
|
|
|
}
|
|
|
|
|
2018-06-28 11:36:25 +03:00
|
|
|
func (o *migrateStatusOptions) run() error {
|
2018-06-24 16:40:48 +03:00
|
|
|
dbURL, err := url.Parse(o.EC.Config.Endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "error parsing Endpoint")
|
|
|
|
}
|
|
|
|
|
|
|
|
dbURL.Scheme = "hasuradb"
|
|
|
|
dbURL.User = url.UserPassword("admin", o.EC.Config.AccessKey)
|
2018-06-28 11:36:57 +03:00
|
|
|
status, err := util.ExecuteStatus("file://"+o.EC.MigrationDir, dbURL.String())
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "cannot fetch migrate status")
|
|
|
|
}
|
|
|
|
o.EC.Logger.Println(status)
|
|
|
|
return nil
|
2018-06-24 16:40:48 +03:00
|
|
|
}
|