Run PostgreSQL Lint Checks in GitHub Actions
Dan Lynch
Give your custom runner an npm script so developers and CI run the same rules:
bashnpm pkg set 'scripts.lint:sql=node lint-sql.mjs' npm run lint:sql
Commit the npm manifest and lockfile, the two lint scripts, and the migration. For a repository with the npm project at its root, add .github/workflows/sql-lint.yml:
yamlname: SQL lint on: pull_request permissions: contents: read jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '22' cache: npm - run: npm ci - run: npm run lint:sql
Open a test pull request that removes the schema from the function name. The check should fail and show the file and line. Put the schema back and confirm the check passes.
Keep reported parse errors blocking, but don't treat a clean lint run as proof of valid SQL. The linter can miss syntax errors inside quoted function bodies. Validate migrations separately on disposable PostgreSQL with check_function_bodies left on. For this lab, create the app_public.documents table first, then run psql -X -v ON_ERROR_STOP=1 -f migrations/001.sql.
For a gradual rollout, add severity: { 'qualified-function-name': 'warn' } next to rules in createLinter. The runner still prints the finding, but a warning doesn't fail CI. Remove the override when the team is ready to enforce the rule.
For checks that need a running database, add a separate Safegres audit.

