build-database
Skill0 starsChanged 12 days agoMITView on GitHub
Design schemas and make production-safe database changes (constraints, indexes, EXPLAIN, N+1, expand/contract migrations, online index builds, batched backfills, isolation, pooling, backups) with approval gates for destructive SQL. Use when writing migrations, changing a schema, adding indexes, tuning slow queries or ORM code. Not for API logic (use `build-backend`).
In this repository33 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- global/CLAUDE.mdCLAUDE.md
- build-backendSkill
- build-commitsSkill
- build-containersSkill
- build-design-systemSkill
- build-frontendSkill
- build-iacSkill
- build-project-setupSkill
- core-documentationSkill
- core-prompt-engineeringSkill
- core-token-efficiencySkill
- create-marketing-copySkill
- create-seo-contentSkill
- operate-incidentSkill
- operate-observabilitySkill
- plan-architectureSkill
- plan-campaignSkill
- plan-codebase-analysisSkill
- plan-test-strategySkill
- plan-threat-modelSkill
- review-pull-requestSkill
- review-seoSkill
- review-ui-uxSkill
- secure-code-reviewSkill
- secure-repo-governanceSkill
- secure-supply-chainSkill
- ship-ci-cdSkill
- ship-github-actionsSkill
- ship-readinessSkill
- ship-releaseSkill
- test-performanceSkill
- test-validationSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 7 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Test: run migrations up (and down if supported) against a fresh database and against a copy with realistic data.
- Distinctive: line 21
Never edit or delete a migration that has been applied anywhere shared.
- Distinctive: line 22
Every migration must be compatible with both the currently deployed app version and the new one (deploys are not atomic).
- Distinctive: line 33
Read plans from the inside out.
- Very specific: line 35
Keep transactions short; no network calls or user waits inside.
- Very specific: line 41
Read references/engine-notes.md when the engine is PostgreSQL, MySQL/MariaDB, SQL Server or SQLite and lock behaviour or syntax matters.
- Distinctive: line 44
Never run against production or shared databases without explicit approval in the current conversation.
- Very specific: line 46
Run manual data fixes inside an explicit transaction, check affected row counts before COMMIT, and keep them in a reviewed script, not ad …
- Distinctive: line 47
Never print connection strings, passwords or production rows containing personal data.
- Distinctive: line 48
Ask before adding extensions, changing pool or server settings, or adding a new datastore.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Engineering
Change schemas and queries so data stays correct, production stays online, and every change can be rolled forward or back.
Procedure
- Identify the setup: engine and version, migration tool and folder, schema source of truth (migrations vs ORM models vs schema file), ORM/query builder, how migrations run in deploys (before/after app rollout, which user), connection pooler, table sizes for touched tables (ask or query catalog stats in a non-production copy).
- Read the current schema for affected tables: columns, types, nullability, defaults, constraints, indexes, foreign keys, triggers, and every query that touches them (search repositories, ORM models, raw SQL, reports, other services).
- Design the change. Model constraints in the database, not only in code:
NOT NULL,CHECK,UNIQUE, foreign keys, correct types. Readreferences/query-tuning.mdwhen adding indexes or a query is slow. - Classify migration risk for the engine and table size. Read
references/safe-migrations.mdbefore writing any migration on a table that has production data. Anything that rewrites the table, takes an exclusive lock for longer than a moment, or breaks the running app version needs the expand/contract sequence. - Write the migration: one logical change per migration, idempotent where the tool allows (
IF NOT EXISTS), with lock and statement timeouts, a down/rollback step or a written roll-forward plan, and schema changes separate from data backfills. - Update data-access code: parameterised queries only; select explicit columns; eager-load or batch to avoid N+1; transactions around multi-statement writes; handle unique-violation and serialization/deadlock errors explicitly.
- Test: run migrations up (and down if supported) against a fresh database and against a copy with realistic data; run repository/integration tests on the real engine (containers), not a substitute; for query changes, compare
EXPLAINbefore and after with production-like row counts. - Plan the rollout: order of migration vs app deploy, backfill duration estimate, monitoring (locks, replication lag, error rates), rollback trigger. Hand release coordination to
ship-readiness.
Rules
- Never edit or delete a migration that has been applied anywhere shared; add a new one. Never let an ORM auto-sync the schema in shared environments.
- Every migration must be compatible with both the currently deployed app version and the new one (deploys are not atomic). Renames and type changes therefore become: add new -> dual write/backfill -> switch reads -> stop writing old -> drop old, over separate deploys.
- Indexing:
Rule Detail Index for real queries WHERE, JOIN, ORDER BY columns of frequent or slow queries; not "every column" Composite order equality columns first, then range, then sort; leftmost-prefix rule applies Selectivity low-cardinality columns (booleans, status) alone rarely help; use partial/filtered indexes Covering include selected columns ( INCLUDE) to enable index-only scans for hot readsForeign keys index the referencing column (Postgres does not do it automatically) Cost each index slows writes and uses memory; drop unused and duplicate indexes (after checking usage stats) Functions WHERE lower(email) = ?needs an expression index or a case-insensitive type - Read plans from the inside out; red flags: sequential/full scans on large tables in hot paths, estimated vs actual rows off by 10x+, nested loops over large outer sets, sorts or hashes spilling to disk, "Using filesort/temporary".
- N+1: one query per row in a loop. Fix with joins,
IN (...)batching, ORM eager loading, or DataLoader-style batching; verify by counting queries in a test. - Keep transactions short; no network calls or user waits inside. Lock rows in a consistent order to avoid deadlocks. Use
SELECT ... FOR UPDATE(orSKIP LOCKEDfor queues) or optimistic version columns for read-modify-write. Retry on serialization failure and deadlock with backoff. - Know the default isolation level (Postgres and SQL Server: Read Committed; MySQL InnoDB: Repeatable Read). Lost updates and write skew are possible below Serializable; prove the invariant with a constraint or lock.
- Pools: size per instance small (start near 2x CPU cores of the DB host divided across app instances); total connections across all instances and workers must stay below the server limit with headroom; set acquire and statement timeouts; use a pooler for serverless or many small instances. Transaction-mode poolers break session state (session
SET, session advisory locks,LISTEN, some prepared-statement setups). - Types:
timestamptz/UTC for instants,numeric/decimal for money,text/varcharwith CHECK for bounded strings, UUID/ULID or bigint identity keys; avoidfloatfor exact values and enums that change often. - Soft delete only if required; it needs partial unique indexes and filters everywhere. Personal data needs a deletion/retention path.
- Backups: confirm automated backups and point-in-time recovery exist, know RPO/RTO, and test restores on a schedule; a backup never restored is unverified.
- Read
references/engine-notes.mdwhen the engine is PostgreSQL, MySQL/MariaDB, SQL Server or SQLite and lock behaviour or syntax matters.
Safety gates
- Never run against production or shared databases without explicit approval in the current conversation. Default to local or disposable databases.
- Destructive statements (
DROP,TRUNCATE,DELETE/UPDATEwithout a tightWHERE, column drops, type changes that lose data, disabling constraints/triggers): before running, show the exact SQL, the target environment, aSELECT count(*)with the same predicate, the backup/snapshot status, and the rollback plan; then wait for a "yes". - Run manual data fixes inside an explicit transaction, check affected row counts before
COMMIT, and keep them in a reviewed script, not ad hoc. - Never print connection strings, passwords or production rows containing personal data; use masked or sampled output.
- Ask before adding extensions, changing pool or server settings, or adding a new datastore.
Output
## Change
<schema/query change and why>
## Migration plan
| Step | Statement / action | Lock / duration risk | Deploy order | Reversible? |
|---|---|---|---|---|
## Query impact
<queries affected; EXPLAIN before/after summary; indexes added/removed>
## Data safety
Backfill: <batch size, throttle, estimate> | Constraints: <added/validated> | Backup: <status>
## Tests
<migration up/down, repository tests, query count checks; commands and results>
## Rollback
<down migration or roll-forward; trigger to use it>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
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.

