diff --git a/atlasexec/atlas_schema.go b/atlasexec/atlas_schema.go index 200b72a..e0ab1bb 100644 --- a/atlasexec/atlas_schema.go +++ b/atlasexec/atlas_schema.go @@ -20,6 +20,7 @@ type ( DevURL string URL []string // Desired schema URL(s) to push + Schema []string // If set, only the specified schemas are pushed. 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. @@ -98,6 +99,7 @@ type ( Vars VarArgs Context *RunContext DevURL string + Schema []string From, To []string Repo string @@ -116,6 +118,7 @@ type ( Vars VarArgs Context *RunContext DevURL string + Schema []string From, To []string Repo string @@ -128,6 +131,7 @@ type ( Vars VarArgs Context *RunContext DevURL string + Schema []string From, To []string Repo string @@ -148,6 +152,7 @@ type ( Vars VarArgs Context *RunContext DevURL string + Schema []string From, To []string Repo string @@ -160,6 +165,7 @@ type ( Vars VarArgs Context *RunContext DevURL string + Schema []string From, To []string Repo string @@ -248,6 +254,9 @@ func (c *Client) SchemaPush(ctx context.Context, params *SchemaPushParams) (*Sch if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } + if len(params.Schema) > 0 { + args = append(args, "--schema", listString(params.Schema)) + } if params.Tag != "" { args = append(args, "--tag", params.Tag) } @@ -394,6 +403,9 @@ func (c *Client) SchemaPlan(ctx context.Context, params *SchemaPlanParams) (*Sch if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } + if len(params.Schema) > 0 { + args = append(args, "--schema", listString(params.Schema)) + } if len(params.From) > 0 { args = append(args, "--from", listString(params.From)) } @@ -452,6 +464,9 @@ func (c *Client) SchemaPlanList(ctx context.Context, params *SchemaPlanListParam if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } + if len(params.Schema) > 0 { + args = append(args, "--schema", listString(params.Schema)) + } if len(params.From) > 0 { args = append(args, "--from", listString(params.From)) } @@ -498,6 +513,9 @@ func (c *Client) SchemaPlanPush(ctx context.Context, params *SchemaPlanPushParam if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } + if len(params.Schema) > 0 { + args = append(args, "--schema", listString(params.Schema)) + } if len(params.From) > 0 { args = append(args, "--from", listString(params.From)) } @@ -567,6 +585,9 @@ func (c *Client) SchemaPlanLint(ctx context.Context, params *SchemaPlanLintParam if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } + if len(params.Schema) > 0 { + args = append(args, "--schema", listString(params.Schema)) + } if len(params.From) > 0 { args = append(args, "--from", listString(params.From)) } @@ -611,6 +632,9 @@ func (c *Client) SchemaPlanValidate(ctx context.Context, params *SchemaPlanValid if params.DevURL != "" { args = append(args, "--dev-url", params.DevURL) } + if len(params.Schema) > 0 { + args = append(args, "--schema", listString(params.Schema)) + } if len(params.From) > 0 { args = append(args, "--from", listString(params.From)) } diff --git a/atlasexec/atlas_schema_test.go b/atlasexec/atlas_schema_test.go index 55d136b..e86b16b 100644 --- a/atlasexec/atlas_schema_test.go +++ b/atlasexec/atlas_schema_test.go @@ -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 schema", + params: &atlasexec.SchemaPlanParams{ + From: []string{"1", "2"}, + To: []string{"2", "3"}, + Schema: []string{"public", "bupisu"}, + }, + args: `schema plan --format {{ json . }} --schema public,bupisu --from 1,2 --to 2,3 --auto-approve`, + }, { name: "with from to and directives", params: &atlasexec.SchemaPlanParams{ @@ -332,6 +341,15 @@ func TestSchema_PlanPush(t *testing.T) { }, args: "schema plan push --format {{ json . }} --file file://plan.hcl --repo testing-repo --auto-approve", }, + { + name: "with auto-approve and schema", + params: &atlasexec.SchemaPlanPushParams{ + Repo: "testing-repo", + File: "file://plan.hcl", + Schema: []string{"public", "bupisu"}, + }, + args: "schema plan push --format {{ json . }} --schema public,bupisu --file file://plan.hcl --repo testing-repo --auto-approve", + }, { name: "with pending status", params: &atlasexec.SchemaPlanPushParams{ @@ -378,6 +396,14 @@ func TestSchema_PlanLint(t *testing.T) { }, args: "schema plan lint --format {{ json . }} --file file://plan.hcl --auto-approve", }, + { + name: "with file and schema", + params: &atlasexec.SchemaPlanLintParams{ + File: "file://plan.hcl", + Schema: []string{"public", "bupisu"}, + }, + args: "schema plan lint --format {{ json . }} --schema public,bupisu --file file://plan.hcl --auto-approve", + }, } for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { @@ -416,6 +442,14 @@ func TestSchema_PlanValidate(t *testing.T) { }, args: "schema plan validate --file file://plan.hcl --auto-approve", }, + { + name: "with file and schema", + params: &atlasexec.SchemaPlanValidateParams{ + File: "file://plan.hcl", + Schema: []string{"public", "bupisu"}, + }, + args: "schema plan validate --schema public,bupisu --file file://plan.hcl --auto-approve", + }, } for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { @@ -511,6 +545,15 @@ func TestSchema_PlanList(t *testing.T) { }, args: "schema plan list --format {{ json . }} --from env://url --repo atlas://testing-repo --auto-approve", }, + { + name: "with repo and schema", + params: &atlasexec.SchemaPlanListParams{ + Repo: "atlas://testing-repo", + From: []string{"env://url"}, + Schema: []string{"public", "bupisu"}, + }, + args: "schema plan list --format {{ json . }} --schema public,bupisu --from env://url --repo atlas://testing-repo --auto-approve", + }, { name: "with repo and pending", params: &atlasexec.SchemaPlanListParams{ @@ -568,6 +611,14 @@ func TestSchema_Push(t *testing.T) { }, args: "schema push --format {{ json . }} atlas-action", }, + { + name: "with repo and schemas", + params: &atlasexec.SchemaPushParams{ + Name: "atlas-action", + Schema: []string{"public", "bupisu"}, + }, + args: "schema push --format {{ json . }} --schema public,bupisu atlas-action", + }, { name: "with repo and tag", params: &atlasexec.SchemaPushParams{