Skip to content

Commit 1ea18a6

Browse files
committed
chore: add sqlc-vet to github actions for validating queries
1 parent dba0dfa commit 1ea18a6

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,3 +908,27 @@ jobs:
908908
909909
echo "::endgroup::"
910910
done
911+
912+
# sqlc-vet runs a postgres docker container, runs Coder migrations, and then
913+
# runs sqlc-vet to ensure all queries are valid. This catches any mistakes
914+
# in migrations or sqlc queries that makes a query unable to be prepared.
915+
sqlc-vet:
916+
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
917+
needs: changes
918+
# TODO: We should do this on any migration or query changes.
919+
# if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
920+
steps:
921+
- name: Checkout
922+
uses: actions/checkout@v4
923+
with:
924+
fetch-depth: 1
925+
# We need golang to run the migration main.go
926+
- name: Setup Go
927+
uses: ./.github/actions/setup-go
928+
929+
- name: Setup sqlc
930+
uses: ./.github/actions/setup-sqlc
931+
932+
- name: Setup and run sqlc vet
933+
run: |
934+
make sqlc-vet

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ test:
708708
gotestsum --format standard-quiet -- -v -short -count=1 ./...
709709
.PHONY: test
710710

711+
sqlc-vet: test-postgres-docker
712+
echo "--- sqlc vet"
713+
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \
714+
sqlc vet -f coderd/database/sqlc.yaml
715+
711716
# When updating -timeout for this test, keep in sync with
712717
# test-go-postgres (.github/workflows/coder.yaml).
713718
# Do add coverage flags so that test caching works.

coderd/database/sqlc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ sql:
8282
- schema: "./dump.sql"
8383
queries: "./queries"
8484
engine: "postgresql"
85+
# This only works if you are running a local postgres database with the
86+
# schema loaded and migrations run.
87+
database:
88+
uri: "${SQLC_DATABASE_URL}"
89+
rules:
90+
- sqlc/db-prepare
8591
gen:
8692
go:
8793
package: "database"

0 commit comments

Comments
 (0)