Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atlasexec: add the 'migrate push' command #11

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions atlasexec/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ type (
LoginParams struct {
Token string
}
// MigratePushParams are the parameters for the `migrate push` command.
MigratePushParams struct {
Name string
Tag string
DevURL string
DirURL string
DirFormat string
noamcattan marked this conversation as resolved.
Show resolved Hide resolved
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 +150,39 @@ 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.DirFormat != "" {
args = append(args, "--dir-format", params.DirFormat)
}
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)
}
args = append(args, params.Vars.AsArgs()...)
if params.Name == "" {
return "", errors.New("directory name cannot be empty")
}
if params.Tag != "" {
args = append(args, fmt.Sprintf("%s:%s", params.Name, params.Tag))
} else {
args = append(args, params.Name)
}
noamcattan marked this conversation as resolved.
Show resolved Hide resolved
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