Skip to content

chore: validate queries using sqlc-vet in github actions #11163

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 6 commits into from
Dec 12, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Dec 12, 2023

What this does

This runs sqlc vet using our queries and schema for a given commit. The only sql lint rule we currently have is that a query can be prepared against our schema.

This protects us from writing a migration that breaks an existing query, or writing a new query that will not execute.

We unit test almost all of our queries, so this failure will likely be caught in test-go-pg. However, the reported failure will correspond to some number of Go tests, and the output might not be straight forward. sqlc vet will have clearer reporting and easier debugging.

Example

Found a query that does not work: (https://github.com/coder/coder/actions/runs/7186260845/job/19574288356)

--- sqlc vet
# package 
queries/tailnet.sql:101:8: column "tailnet_clients.id" must appear in the GROUP BY clause or be used in an aggregate function

@Emyrk Emyrk changed the title chore: add sqlc-vet to github actions for validating queries chore: validate queries using sqlc-vet in github actions Dec 12, 2023
@Emyrk Emyrk changed the base branch from main to stevenmasley/invalid_tailnet_query December 12, 2023 20:55
Copy link
Member Author

Emyrk commented Dec 12, 2023

Base automatically changed from stevenmasley/invalid_tailnet_query to main December 12, 2023 21:02
@Emyrk Emyrk marked this pull request as ready for review December 12, 2023 21:12
@Emyrk Emyrk force-pushed the stevenmasley/sqlc-vet branch from e10d09e to c34f681 Compare December 12, 2023 21:16
@Emyrk Emyrk force-pushed the stevenmasley/sqlc-vet branch from c34f681 to 2dd66a9 Compare December 12, 2023 21:19
@Emyrk Emyrk requested a review from coadler December 12, 2023 21:21
@Emyrk Emyrk merged commit e52d848 into main Dec 12, 2023
@Emyrk Emyrk deleted the stevenmasley/sqlc-vet branch December 12, 2023 21:53
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants