diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index cdcc157132..559a477581 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -479,3 +479,29 @@ jobs: # For gh CLI. We need a real token since we're commenting on a PR in a # different repo. GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }} + + # publish-sqlc pushes the latest schema to sqlc cloud. + # At present these pushes cannot be tagged, so the last push is always the latest. + publish-sqlc: + name: "Publish to schema sqlc cloud" + runs-on: "ubuntu-latest" + needs: release + if: ${{ !inputs.dry_run }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + # We need golang to run the migration main.go + - name: Setup Go + uses: ./.github/actions/setup-go + + - name: Setup sqlc + uses: ./.github/actions/setup-sqlc + + - name: Push schema to sqlc cloud + # Don't block a release on this + continue-on-error: true + run: | + make sqlc-push diff --git a/Makefile b/Makefile index b3be43fcd6..f1da02f2f5 100644 --- a/Makefile +++ b/Makefile @@ -708,6 +708,27 @@ test: gotestsum --format standard-quiet -- -v -short -count=1 ./... .PHONY: test +# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a +# dependency for any sqlc-cloud related targets. +sqlc-cloud-is-setup: + if [[ "$(SQLC_AUTH_TOKEN)" == "" ]]; then + echo "ERROR: 'SQLC_AUTH_TOKEN' must be set to auth with sqlc cloud before running verify." 1>&2 + exit 1 + fi +.PHONY: sqlc-cloud-is-setup + +sqlc-push: sqlc-cloud-is-setup test-postgres-docker + echo "--- sqlc push" + SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \ + sqlc push -f coderd/database/sqlc.yaml && echo "Passed sqlc push" +.PHONY: sqlc-push + +sqlc-verify: sqlc-cloud-is-setup test-postgres-docker + echo "--- sqlc verify" + SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \ + sqlc verify -f coderd/database/sqlc.yaml && echo "Passed sqlc verify" +.PHONY: sqlc-verify + sqlc-vet: test-postgres-docker echo "--- sqlc vet" SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \ diff --git a/coderd/database/sqlc.yaml b/coderd/database/sqlc.yaml index f8d45d46a1..cb78d25873 100644 --- a/coderd/database/sqlc.yaml +++ b/coderd/database/sqlc.yaml @@ -2,6 +2,9 @@ # It was chosen to ensure type-safety when interacting with # the database. version: "2" +cloud: + # This is the static ID for the coder project. + project: "01HEP08N3WKWRFZT3ZZ9Q37J8X" # Ideally renames & overrides would go under the sql section, but there is a # bug in sqlc that only global renames & overrides are currently being applied. overrides: