Skip to content

Commit

Permalink
atlasexec: add --directive to schema plan
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Oct 14, 2024
1 parent da72e04 commit bf4bcd7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
12 changes: 12 additions & 0 deletions atlasexec/atlas_models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package atlasexec

import (
"errors"
"time"

"ariga.io/atlas/sql/sqlcheck"
Expand Down Expand Up @@ -129,3 +130,14 @@ func (r *SummaryReport) DiagnosticsCount() int {
}
return n
}

// Errors returns the errors in the summary report, if exists.
func (r *SummaryReport) Errors() []error {
var errs []error
for _, f := range r.Files {
if f.Error != "" {
errs = append(errs, errors.New(f.Error))
}
}
return errs
}
10 changes: 7 additions & 3 deletions atlasexec/atlas_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ type (
Context *RunContext
DevURL string

From, To []string
Repo string
Name string
From, To []string
Repo string
Name string
Directives []string
// The below are mutually exclusive and can be replaced
// with the 'schema plan' sub-commands instead.
DryRun bool // If false, --auto-approve is set.
Expand Down Expand Up @@ -418,6 +419,9 @@ func (c *Client) SchemaPlan(ctx context.Context, params *SchemaPlanParams) (*Sch
} else {
args = append(args, "--auto-approve")
}
for _, d := range params.Directives {
args = append(args, "--directive", d)
}
// NOTE: This command only support one result.
return firstResult(jsonDecode[SchemaPlan](c.runCommand(ctx, args)))
}
Expand Down
9 changes: 9 additions & 0 deletions atlasexec/atlas_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ func TestSchema_Plan(t *testing.T) {
},
args: `schema plan --format {{ json . }} --from 1,2 --to 2,3 --auto-approve`,
},
{
name: "with from to and directives",
params: &atlasexec.SchemaPlanParams{
From: []string{"1", "2"},
To: []string{"2", "3"},
Directives: []string{"atlas:nolint", "\"atlas:txmode none\""},
},
args: `schema plan --format {{ json . }} --from 1,2 --to 2,3 --auto-approve --directive atlas:nolint --directive "atlas:txmode none"`,
},
{
name: "with config",
params: &atlasexec.SchemaPlanParams{
Expand Down

0 comments on commit bf4bcd7

Please sign in to comment.