mirror of
https://github.com/foomo/posh-providers.git
synced 2025-10-16 12:35:41 +00:00
feat(golang-migrate/migrate): add op
This commit is contained in:
parent
297c2fffca
commit
ea379e0276
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/foomo/posh-providers/onepassword"
|
||||||
"github.com/foomo/posh/pkg/command/tree"
|
"github.com/foomo/posh/pkg/command/tree"
|
||||||
"github.com/foomo/posh/pkg/log"
|
"github.com/foomo/posh/pkg/log"
|
||||||
"github.com/foomo/posh/pkg/prompt/goprompt"
|
"github.com/foomo/posh/pkg/prompt/goprompt"
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
Command struct {
|
Command struct {
|
||||||
l log.Logger
|
l log.Logger
|
||||||
|
op *onepassword.OnePassword
|
||||||
name string
|
name string
|
||||||
config Config
|
config Config
|
||||||
configKey string
|
configKey string
|
||||||
@ -41,6 +43,12 @@ func CommandWithConfigKey(v string) CommandOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CommandWithOnePassword(v *onepassword.OnePassword) CommandOption {
|
||||||
|
return func(o *Command) {
|
||||||
|
o.op = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// ~ Constructor
|
// ~ Constructor
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -109,6 +117,17 @@ func NewCommand(l log.Logger, opts ...CommandOption) (*Command, error) {
|
|||||||
},
|
},
|
||||||
Execute: inst.execute,
|
Execute: inst.execute,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "migrate",
|
||||||
|
Description: "Migrates either up or down to the specified version",
|
||||||
|
Args: tree.Args{
|
||||||
|
{
|
||||||
|
Name: "version",
|
||||||
|
Description: "Version to migrate",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Execute: inst.execute,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Description: "Print the current version of the database",
|
Description: "Print the current version of the database",
|
||||||
@ -161,6 +180,14 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
|
|||||||
database := c.config.Database(r.Args().At(0))
|
database := c.config.Database(r.Args().At(0))
|
||||||
source := c.config.Source(r.Args().At(1))
|
source := c.config.Source(r.Args().At(1))
|
||||||
|
|
||||||
|
if c.op != nil {
|
||||||
|
if out, err := c.op.Render(ctx, database); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
database = string(out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m, err := migrate.New(source, database)
|
m, err := migrate.New(source, database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -192,6 +219,12 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error {
|
|||||||
return m.Down()
|
return m.Down()
|
||||||
case "down-by-one":
|
case "down-by-one":
|
||||||
return m.Steps(-1)
|
return m.Steps(-1)
|
||||||
|
case "migrate":
|
||||||
|
i, err := strconv.Atoi(r.Args().At(3))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return m.Migrate(uint(i))
|
||||||
case "force":
|
case "force":
|
||||||
i, err := strconv.Atoi(r.Args().At(3))
|
i, err := strconv.Atoi(r.Args().At(3))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user