/goal all database migrations apply cleanly — run them, fix schema or SQL errors, repeat until `npx prisma migrate status` is clean; stop after 6 turns
/schedule every night at 3am, dump the live database schema (`pg_dump --schema-only`) and diff it against the schema produced by applying all committed migrations to a fresh scratch database. Verify the scratch build reports `migrate status` clean before comparing. Any drift — columns, indexes, or constraints present in prod but missing from migrations, or vice versa — gets an issue filed with the exact diff attached and a proposed corrective migration for human review. Read-only against production; never modify the live schema. Stop after 1 pass per run.
Instrument the test suite with query logging, find endpoints issuing N+1 queries, and fix them with eager loading or batching until the hot paths are clean.
/goal no endpoint in the integration test suite issues more than 10 SQL queries per request — enable query logging in the test environment, find the worst N+1 offender, fix it with eager loading or a batched query, verify the count dropped and tests still pass, then move to the next; stop after 12 turns
Query the catalog for unindexed foreign keys, create a migration per missing index, and verify each with a full test run until all FKs are covered or 6 turns complete.
/goal every foreign key in the schema has a covering index — query the catalog (pg_catalog or information_schema) to list FKs with no matching index, add one migration per missing index, and re-run the catalog check until it returns zero rows. After each index, apply the migration on a scratch database and run the full test suite to verify nothing regresses; stop after 6 turns. Only add indexes — never change constraints or table definitions — and propose the final migration set as a PR for review.