Skip to content

feat(verify): Add new command to verify queries and migrations #2986

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

Merged
merged 11 commits into from
Nov 21, 2023

Conversation

kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Nov 17, 2023

push

We've renamed the upload sub-command to push. Using upload is supported for now, but please switch over to using push. We changed the data sent along in a push request. Upload used to include the configuration file, migrations, queries, and all generated code. Push drops the generated code in favor of including the [plugin.GenerateRequest], which is the protobuf message we pass to codegen plugins.

We now pass along annotations for each push. By default, we include these environment variables if they are present:

GITHUB_REPOSITORY
GITHUB_REF
GITHUB_REF_NAME
GITHUB_REF_TYPE
GITHUB_SHA

Like upload, push should be run when you tag a release of your application. We run it on every push to main, as we continuously deploy those commits.

verify

The verify command, building on top of the push command, ensures migrations are safe to deploy. Verify sends your current schema and queries to sqlc cloud. There, we run the queries for your latest push against your new schema changes. This check catches backwards incompatible schema changes for existing queries.

@kyleconroy kyleconroy changed the title feat(push): Include different information when uploading archives feat(verify): Add new command to verify migrations Nov 17, 2023
@kyleconroy kyleconroy marked this pull request as ready for review November 17, 2023 20:50
Comment on lines +78 to +85
func annotate() map[string]string {
labels := map[string]string{}
for _, ev := range envvars {
key := strings.ReplaceAll(strings.ToLower(ev), "_", ".")
labels[key] = os.Getenv(ev)
}
outs, err := readOutputs(up.dir, result)
return labels
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's frowned upon these days but this seems like a case for init()

var pushCmd = &cobra.Command{
Use: "push",
Aliases: []string{"upload"},
Short: "Push the schema, queries, and configuration to your project",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be "...for this project" which is maybe not ideal but I think is clearer than "...to your project"

}
p := &pusher{}
if err := Process(ctx, p, dir, filename, opts); err != nil {
os.Exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just be return err no?


var verifyCmd = &cobra.Command{
Use: "verify",
Short: "Verify schema, queries, and configuration against main",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "against main" means anything here. I don't have a better idea at the moment, but I think just saying "Verify schema, queries, and configuration for this project" would be fine for now.

Comment on lines 45 to 46
// hmmm
os.Exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't just return err here?

@kyleconroy kyleconroy changed the title feat(verify): Add new command to verify migrations feat(verify): Add new command to verify queries and migrations Nov 21, 2023
@kyleconroy kyleconroy merged commit 64313a6 into main Nov 21, 2023
@kyleconroy kyleconroy deleted the kyle/sqlc-push branch November 21, 2023 17:07
@kyleconroy kyleconroy restored the kyle/sqlc-push branch November 21, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants