Build a Nightly SQL Review Bot with Free Models and a Free Server
Description and use
A nightly SQL review bot uses free models and a local server to automatically scan merged queries, identify production risks, and publish a report.
Problem
A costly JOIN without an index stalled the checkout pipeline for six minutes and was missed in code review.
Outcome
The bot runs nightly, identifies missing filters, limits, and inefficient joins, and outputs a concise report, reducing manual review effort.
Workflow
- Deploy a free local server (Docker or Kubernetes) exposing an OpenAI-compatible API.
- Configure the client to use the free model via the local endpoint.
- Write a script that extracts SQL statements from commits made since midnight and sends each to the local model for review.
- Schedule the script to run nightly (cron or GitHub Actions).
- Evaluate the bot against a labeled dataset and adjust expectations with a decision table.
Evidence
Pre-commit hooks interrupt developers. They create friction, prompt rework, and get disabled after the third false positive.
A nightly bot runs after everyone goes home. It scans the queries merged during the day, flags risky patterns, and posts a report to a channel or file.
- Record date: 2026-09-05T18:22:33.254Z