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: support schema for SchemaPush #107

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions atlasexec/atlas_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -98,6 +99,7 @@ type (
Vars VarArgs
Context *RunContext
DevURL string
Schema []string

From, To []string
Repo string
Expand All @@ -116,6 +118,7 @@ type (
Vars VarArgs
Context *RunContext
DevURL string
Schema []string

From, To []string
Repo string
Expand All @@ -128,6 +131,7 @@ type (
Vars VarArgs
Context *RunContext
DevURL string
Schema []string

From, To []string
Repo string
Expand All @@ -148,6 +152,7 @@ type (
Vars VarArgs
Context *RunContext
DevURL string
Schema []string

From, To []string
Repo string
Expand All @@ -160,6 +165,7 @@ type (
Vars VarArgs
Context *RunContext
DevURL string
Schema []string

From, To []string
Repo string
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down
51 changes: 51 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 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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down