Skip to content

Commit

Permalink
atlasexec: add the 'migrate push' command
Browse files Browse the repository at this point in the history
  • Loading branch information
noamcattan committed Aug 28, 2023
1 parent 4e4b32c commit 17d397e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions atlasexec/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ type (
LoginParams struct {
Token string
}
// MigratePushParams are the parameters for the `migrate push` command.
MigratePushParams struct {
Name string
Tag string
DevURL string
DirURL string
LockTimeout string
ConfigURL string
Env string
Vars Vars
}
// MigrateApplyParams are the parameters for the `migrate apply` command.
MigrateApplyParams struct {
Env string
Expand Down Expand Up @@ -138,6 +149,36 @@ func (c *Client) Logout(ctx context.Context) error {
return err
}

// MigratePush runs the 'migrate push' command.
func (c *Client) MigratePush(ctx context.Context, params *MigratePushParams) (string, error) {
args := []string{"migrate", "push"}
if params.DevURL != "" {
args = append(args, "--dev-url", params.DevURL)
}
if params.DirURL != "" {
args = append(args, "--dir", params.DirURL)
}
if params.LockTimeout != "" {
args = append(args, "--lock-timeout", params.LockTimeout)
}
if params.ConfigURL != "" {
args = append(args, "--config", params.ConfigURL)
}
if params.Env != "" {
args = append(args, "--env", params.Env)
}
if params.Name == "" {
return "", errors.New("directory name cannot be empty")
}
args = append(args, params.Vars.AsArgs()...)
if params.Tag != "" {
args = append(args, fmt.Sprintf("%s:%s", params.Name, params.Tag))
} else {
args = append(args, params.Name)
}
return stringVal(c.runCommand(ctx, args))
}

// MigrateApply runs the 'migrate apply' command.
func (c *Client) MigrateApply(ctx context.Context, params *MigrateApplyParams) (*MigrateApply, error) {
args := []string{"migrate", "apply", "--format", "{{ json . }}"}
Expand Down

0 comments on commit 17d397e

Please sign in to comment.