-
Notifications
You must be signed in to change notification settings - Fork 278
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
Add "auto approve" flag to "schema apply" command #526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd/action/apply.go
Outdated
@@ -53,6 +54,7 @@ func init() { | |||
ApplyCmd.Flags().BoolVarP(&ApplyFlags.DryRun, "dry-run", "", false, "Dry-run. Print SQL plan without prompting for execution") | |||
ApplyCmd.Flags().StringVarP(&ApplyFlags.Addr, "addr", "", "127.0.0.1:5800", "used with -w, local address to bind the server to") | |||
ApplyCmd.Flags().StringSliceVarP(&ApplyFlags.Schema, "schema", "s", nil, "Set schema name") | |||
ApplyCmd.Flags().BoolVarP(&ApplyFlags.AutoApprove, "approve", "", false, "Auto approve. Apply the schema changes without prompting for approval") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd try to be more in line what flags like this are usually called. So I propose for --force
/ -f
or --no-interaction
or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with --auto-approve
because I felt like --force
/ -f
would conflict with the existing -f
argument. Open to other ideas too
cmd/action/apply.go
Outdated
if autoApprove { | ||
schemaCmd.Println("Applying changes (automatically approved with --approve flag)") | ||
err = d.ApplyChanges(ctx, changes) | ||
cobra.CheckErr(err) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put the prompt in an extra func and only do this:
if autoApprove || promptUser() {
cobra.CheckErr(d.ApplyChanges(ctx, changes))
}
When running the integration tests, some of the tests failed. But the new one I added appeared to pass. Let me know if you'd like me to change anything there. I've included details below for how I ran the tests in case I did something incorrectly
And here are the failures I got
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Regarding your local tests: are you sure the docker containers were clean? Maybe there have been some left over data. This happens sometimes if you stop the test mid run. They don't get cleaned properly then.
} | ||
|
||
func applyRun(d *Driver, dsn string, file string, dryRun bool) { | ||
func applyRun(d *Driver, dsn string, file string, dryRun bool, autoApprove bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rotemtam should we introduce a small config struct here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but can be done in additional PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well done @ericyd ,
notice that CI is red, please run go generate ./...
to update the CLI documentation after your flag addition. thanks!
- rename flag to "auto-approve" - refactor user prompt into new function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job @ericyd, thanks for your contribution!
Closes #519
Summary
--approve
boolean flag toschema apply
command. Default: false. When true, applies schema changes to given DSN without prompting user for approval. Useful for CI environmentsNotes
--approve
instead of--apply
because I felt like runningatlas schema apply --apply
would feel kind of strange, but I'm totally open to other naming options.Docker Compose config:
Steps
docker-compose run --rm --service-ports go bash
docker-compose exec db bash
psql dev -U postgres
create table testing (id text, name text); \q
createdb testing -U postgres
cd app && go run ./cmd/atlas schema inspect -d "$DB_URL" > atlas.hcl
go run ./cmd/atlas schema apply -d "postgres://postgres:postgres@db:5432/testing?sslmode=disable" -f atlas.hcl --approve
To run the integration tests, I followed the general idea from
.github/workflows/ci.yml
: