Skip to content

Commit

Permalink
atlasexec: added URL params to schema/push (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm authored Sep 24, 2024
1 parent 9892aaf commit 8a1a483
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
12 changes: 12 additions & 0 deletions atlasexec/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,18 @@ func jsonDecodeErr[T any](fn func([]*T, string) error) func(io.Reader, error) ([
}
}

// repeatFlag repeats the flag for each value.
func repeatFlag(flag string, values []string) []string {
if len(values) == 0 {
return nil
}
out := make([]string, 0, len(values)*2)
for _, v := range values {
out = append(out, flag, v)
}
return out
}

func listString(args []string) string {
return strings.Join(args, ",")
}
Expand Down
12 changes: 7 additions & 5 deletions atlasexec/atlas_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ type (
Context *RunContext
DevURL string

Name string // Name of the schema (repo) to push to.
Tag string // Tag to push the schema with
Version string // Version of the schema to push. Defaults to the current timestamp.
Description string // Description of the schema changes.
URL []string // Desired schema URL(s) to push
Name string // Name of the schema (repo) to push to.
Tag string // Tag to push the schema with
Version string // Version of the schema to push. Defaults to the current timestamp.
Description string // Description of the schema changes.
}
// SchemaPush represents the result of a 'schema push' command.
SchemaPush struct {
Expand All @@ -37,7 +38,7 @@ type (
DevURL string

URL string
To string
To string // TODO: change to []string
TxMode string
Exclude []string
Schema []string
Expand Down Expand Up @@ -241,6 +242,7 @@ func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (*Sch
args = append(args, "--context", string(buf))
}
// Flags of the 'schema push' sub-commands
args = append(args, repeatFlag("--url", params.URL)...)
if params.DevURL != "" {
args = append(args, "--dev-url", params.DevURL)
}
Expand Down
14 changes: 14 additions & 0 deletions atlasexec/atlas_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,20 @@ func TestSchema_Push(t *testing.T) {
params: &atlasexec.SchemaPushParams{},
args: "schema push --format {{ json . }}",
},
{
name: "push with 1 URL",
params: &atlasexec.SchemaPushParams{
URL: []string{"file://foo.hcl"},
},
args: "schema push --format {{ json . }} --url file://foo.hcl",
},
{
name: "push with 2 URLs",
params: &atlasexec.SchemaPushParams{
URL: []string{"file://foo.hcl", "file://bupisu.hcl"},
},
args: "schema push --format {{ json . }} --url file://foo.hcl --url file://bupisu.hcl",
},
{
name: "with repo",
params: &atlasexec.SchemaPushParams{
Expand Down

0 comments on commit 8a1a483

Please sign in to comment.