agentleFS
CaduS0uzaCaduS0uza/qa-supreme/skills/database-testing/SKILL.md

database-testing

Skill1 starsChanged 2 months agoMITView on GitHub

Test the data layer — migrations forward and back, constraints, transactions, tenant scoping in queries, and the row-level policies that decide who sees what. Use when the change touches schema, migrations, queries, RLS policies, or when data integrity is the risk.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every migration is tested in three directions, on a copy of production-shaped data — never on an empty schema, where every migration passes:

    line 13
  2. Distinctive:

    Prefer a constraint over a test where you can, then test that the constraint exists:

    line 33
  3. Very specific:

    Test the policy at the database, not through the app: an ORM filter is one forgotten where away from a leak, and the policy is the layer …

    line 49
  4. Distinctive:

    Test the isolation level you actually run in — read-committed and serializable behave differently under exactly the interleaving that will …

    line 58

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Database Testing

Application bugs are annoying. Data bugs are permanent: by the time you find them, the wrong rows have been wrong for weeks and there is no rollback for that.

Migrations

Every migration is tested in three directions, on a copy of production-shaped data — never on an empty schema, where every migration passes:

  1. Forward on a database with real volume and real edge rows (nulls, legacy encodings, the row created before the column existed).
  2. Backward, or a written forward-fix plan if the migration is genuinely irreversible. "We won't need to roll back" is not a plan.
  3. Both at once: the old code against the new schema. Deploys are not atomic, so for a window the previous version is talking to the migrated database. That window is where the incident lives.

Additive first (add column nullable → backfill → start writing → make required → drop old) is what makes that window safe. Test each step as its own deploy.

-- the backfill nobody tests: does it terminate, and does it lock the table?
EXPLAIN (ANALYZE, BUFFERS) UPDATE orders SET total_cents = ROUND(total * 100) WHERE total_cents IS NULL;

Constraints are tests that run in production

Prefer a constraint over a test where you can, then test that the constraint exists:

  • NOT NULL, UNIQUE, foreign keys with the right ON DELETE, CHECK (amount_cents >= 0).
  • Try to insert the violating row and assert the database refuses it. A constraint nobody tested has a real chance of never having been applied.
  • Assert the index that the hot query depends on exists — a dropped index is a silent outage.

Tenant scoping and row-level security

The highest-value data test in a multi-tenant product:

SET request.jwt.claims = '{"sub":"user-b","tenant":"globex"}';
SELECT count(*) FROM orders WHERE tenant = 'acme';   -- must be 0, not "the app filters it"

Test the policy at the database, not through the app: an ORM filter is one forgotten where away from a leak, and the policy is the layer that survives that mistake. Prove each policy with mutation-proof — drop it and confirm the test goes red.

Transactions and concurrency

  • Multi-step writes are one transaction; assert that a failure in the middle leaves nothing.
  • Two clients writing the same row: exactly one wins, the loser gets a coherent error (test with two connections, not two sequential calls).
  • Test the isolation level you actually run in — read-committed and serializable behave differently under exactly the interleaving that will happen in production.
  • Deadlock path: acquire in a fixed order, and test that the retry converges.

Test data

Rolled-back transaction per test, or a namespace per worker (test-data-management). Never a shared seed database — that is where order-dependent flake is born.

Done means

Migration tested in all three directions with timings on production-shaped volume, constraints proven by rejected inserts, scoping proven by a query that returns zero rows for the wrong tenant.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.