From ea379e0276dbcd671d5d792a7f5c3dd6f47f558b Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Wed, 4 Dec 2024 10:56:34 +0100 Subject: [PATCH] feat(golang-migrate/migrate): add op --- golang-migrate/migrate/command.go | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/golang-migrate/migrate/command.go b/golang-migrate/migrate/command.go index 9a93172..7312bb9 100644 --- a/golang-migrate/migrate/command.go +++ b/golang-migrate/migrate/command.go @@ -4,6 +4,7 @@ import ( "context" "strconv" + "github.com/foomo/posh-providers/onepassword" "github.com/foomo/posh/pkg/command/tree" "github.com/foomo/posh/pkg/log" "github.com/foomo/posh/pkg/prompt/goprompt" @@ -17,6 +18,7 @@ import ( type ( Command struct { l log.Logger + op *onepassword.OnePassword name string config Config 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 // ------------------------------------------------------------------------------------------------ @@ -109,6 +117,17 @@ func NewCommand(l log.Logger, opts ...CommandOption) (*Command, error) { }, 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", 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)) 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) if err != nil { return err @@ -192,6 +219,12 @@ func (c *Command) execute(ctx context.Context, r *readline.Readline) error { return m.Down() case "down-by-one": 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": i, err := strconv.Atoi(r.Args().At(3)) if err != nil {