AI writes database logic fast. A silent mistake there costs the most and is hardest to catch by eye.
Generated tests pin how each routine behaves today
The assistant runs them before reporting back
A failure you did not ask for means fix the code
Intended change means regenerate, re-pin and commit
How to do it
Generate tests that pin today's behaviour and commit them:
unitautogen --schema public --out unit_tests --html report.html --json report.json
Give your AI tool the guardrail rule below, so it runs the committed tests on every change.
Wire the same tests into CI; a behaviour it altered fails before merge.
The mistake no code review catches
You ask for a new tier. The assistant quietly changes >= 1000 to > 1000.
The edit reads fine and ships. A customer with exactly 1000 points drops a tier.
With the guardrail, the committed test for 1000 fails first. have: silver, want: gold.
The assistant fixes the boundary, re-runs green, then adds the new tier's tests.
Set it once
One rule in AGENTS.md or .cursor/rules:
Use UnitAutogen as the guardrail for all database work.
Whenever you add or change a function, procedure, trigger or RLS policy:
1. Run the committed guardrail tests first.
2. If a test fails and I did NOT ask for that behaviour to change, the
code is wrong. Fix the code and re-run. Never edit a test to pass.
3. If this is new logic, or I confirmed the change was intended,
regenerate the tests, run them, and commit them with the migration.
4. Tell me which tests ran, the pass/fail count, and what you regenerated.
You type feature requests; you never run a command
Automated tests in CI are how the platform says to catch a change before production.
Supabase encourages automated pgTAP tests, run in CI with supabase test db. UnitAutogen generates them, so a change (AI or human) that breaks behaviour fails there. Supabase, Testing your database →
Supabase ships pgTAP as its unit-testing extension. UnitAutogen emits standard pgTAP you commit and gate CI on. Supabase, pgTAP unit testing →
Your privacy
We would like to log your visit to see how the site is used. That records the page, the site you came from, your IP address and browser, and a random id for this tab. We delete it once we no longer need it.