Build database changes as auditable, reversible, and verified operations.
Non-negotiable behavior
- Do not assume schema, indexes, or constraints. Verify by reading migrations/schema files or introspecting the DB when available.
- Do not guess query plans or performance. Verify with
EXPLAIN / EXPLAIN ANALYZE when possible.
- Do not propose destructive operations without a rollback and explicit approval.
- Separate facts (schema, constraints, measured plans) from hypotheses (suspected bottlenecks).
Use this skill when
- designing tables, relations, constraints, or indexes
- planning or reviewing migrations
- writing SQL queries or query builders
- debugging performance issues
- enforcing tenancy, privacy, and access boundaries in data models
- adding audit logs, soft deletes, retention, or compliance controls
Database design priorities (agentic products)
Agentic products tend to need:
- run and step logs (replayable traces)
- tool receipts (what changed / where / why)
- artifacts (plans, outputs, generated files)
- approvals (requested/approved/denied with scope)
- eval results (golden/adversarial/regression history)
Your schema should support:
- correct querying at scale
- isolation across tenants/users
- cost-effective retention (hot vs cold storage)
- legal/compliance deletion and export paths
Procedure: schema or migration work
1. Establish ground truth
Collect:
- existing schema (DDL or ORM models)
- current migrations
- data volume estimates (rows, growth)
- access patterns (reads/writes, most frequent queries)
- privacy requirements (PII fields, retention, redaction)
- tenancy model (single-tenant vs multi-tenant)
If you cannot access an actual DB, state the limitation and proceed with file-based verification only.
2. Define the data contract
For each entity/table:
- primary key strategy
- required fields and nullability
- uniqueness rules
- foreign keys and cascade strategy
- soft delete strategy (if any)
- timestamps and ordering fields
- audit fields (who/what/when)
3. Design for access patterns
For each top query:
- write the query shape
- decide required indexes
- choose covering vs selective indexes
- decide partitioning strategy if needed
4. Plan migrations safely
For each migration:
- classify: additive / backfill / constraint / destructive
- ensure idempotency where feasible
- ensure backward compatibility across deploys when needed
- add a rollback path (down migration or compensating migration)
Safe migration patterns
- Add new nullable column → backfill in batches → add constraint/default → flip reads/writes → remove old column later.
- Create index concurrently (where supported) to reduce lock impact.
- Introduce new table + dual write → migrate reads → remove old path.
5. Transactions and consistency
Be explicit about:
- transaction boundaries
- isolation needs
- idempotency keys for side effects
- uniqueness constraints that enforce invariants (not just app code)
6. Multi-tenant and privacy boundaries
If multi-tenant:
- include
tenant_id on every tenant-scoped table
- enforce tenant scoping in queries (and ideally in DB constraints/policies when available)
- avoid cross-tenant joins unless explicitly required and audited
For privacy:
- separate PII fields when helpful
- minimize indexing on sensitive fields
- define retention and deletion behavior
7. Verification checklist (must do)
- Validate schema changes against the existing models/migrations.
- Validate queries against real or representative schema.
- For performance changes, provide
EXPLAIN results or clearly state when unavailable.
- Ensure roll-forward and rollback procedures exist.
- Ensure invariants are enforced by constraints where appropriate.
Query review checklist
- Correctness: joins, filters, null semantics
- Tenancy:
tenant_id scoping present and indexed
- Safety: no SQL injection, parameters used
- Performance: index usage, avoid N+1 patterns
- Locking: avoid long transactions; beware
SELECT ... FOR UPDATE blast radius
- Pagination: stable ordering; no offset pitfalls at scale (prefer keyset pagination)
Recommended schemas for agentic systems (templates)
If relevant, propose tables like:
runs: one row per user-visible run
run_steps: one row per step with state transitions
tool_calls: tool name, validated args summary, timings, errors
tool_receipts: what changed/where/why/next + artifact pointers
approvals: requested action, scope, decision, approver, expiry
artifacts: blobs/paths, provenance, retention policy
eval_runs: eval suite runs + metrics + thresholds
Output contract
When asked for DB work, return:
- Verified facts (schema, constraints, observed plans)
- Proposed change (DDL/migration steps)
- Why (access patterns + invariants)
- Risk analysis (locks, backfill cost, downtime risk)
- Rollback plan
- Verification plan (queries, explain, tests)
Stop conditions
Stop and require explicit approval before:
- dropping columns/tables or destructive backfills
- long-running migrations in production
- changing retention/deletion semantics
- exporting or touching sensitive data
1---2name: database-agent-engineer3description: Database engineering skill for agentic systems. Use for schema design, migrations, query correctness, performance, transactions, multi-tenant boundaries, privacy, backups/rollback, and safe DB operations.4---56Build database changes as **auditable, reversible, and verified** operations.78## Non-negotiable behavior9- Do not assume schema, indexes, or constraints. **Verify** by reading migrations/schema files or introspecting the DB when available.10- Do not guess query plans or performance. **Verify** with `EXPLAIN` / `EXPLAIN ANALYZE` when possible.11- Do not propose destructive operations without a rollback and explicit approval.12- Separate **facts** (schema, constraints, measured plans) from **hypotheses** (suspected bottlenecks).1314## Use this skill when15- designing tables, relations, constraints, or indexes16- planning or reviewing migrations17- writing SQL queries or query builders18- debugging performance issues19- enforcing tenancy, privacy, and access boundaries in data models20- adding audit logs, soft deletes, retention, or compliance controls2122## Database design priorities (agentic products)23Agentic products tend to need:24- **run and step logs** (replayable traces)25- **tool receipts** (what changed / where / why)26- **artifacts** (plans, outputs, generated files)27- **approvals** (requested/approved/denied with scope)28- **eval results** (golden/adversarial/regression history)2930Your schema should support:31- correct querying at scale32- isolation across tenants/users33- cost-effective retention (hot vs cold storage)34- legal/compliance deletion and export paths3536## Procedure: schema or migration work37### 1. Establish ground truth38Collect:39- existing schema (DDL or ORM models)40- current migrations41- data volume estimates (rows, growth)42- access patterns (reads/writes, most frequent queries)43- privacy requirements (PII fields, retention, redaction)44- tenancy model (single-tenant vs multi-tenant)4546If you cannot access an actual DB, state the limitation and proceed with file-based verification only.4748### 2. Define the data contract49For each entity/table:50- primary key strategy51- required fields and nullability52- uniqueness rules53- foreign keys and cascade strategy54- soft delete strategy (if any)55- timestamps and ordering fields56- audit fields (who/what/when)5758### 3. Design for access patterns59For each top query:60- write the query shape61- decide required indexes62- choose covering vs selective indexes63- decide partitioning strategy if needed6465### 4. Plan migrations safely66For each migration:67- classify: additive / backfill / constraint / destructive68- ensure idempotency where feasible69- ensure backward compatibility across deploys when needed70- add a rollback path (down migration or compensating migration)7172#### Safe migration patterns73- Add new nullable column → backfill in batches → add constraint/default → flip reads/writes → remove old column later.74- Create index concurrently (where supported) to reduce lock impact.75- Introduce new table + dual write → migrate reads → remove old path.7677### 5. Transactions and consistency78Be explicit about:79- transaction boundaries80- isolation needs81- idempotency keys for side effects82- uniqueness constraints that enforce invariants (not just app code)8384### 6. Multi-tenant and privacy boundaries85If multi-tenant:86- include `tenant_id` on every tenant-scoped table87- enforce tenant scoping in queries (and ideally in DB constraints/policies when available)88- avoid cross-tenant joins unless explicitly required and audited8990For privacy:91- separate PII fields when helpful92- minimize indexing on sensitive fields93- define retention and deletion behavior9495### 7. Verification checklist (must do)96- Validate schema changes against the existing models/migrations.97- Validate queries against real or representative schema.98- For performance changes, provide `EXPLAIN` results or clearly state when unavailable.99- Ensure roll-forward and rollback procedures exist.100- Ensure invariants are enforced by constraints where appropriate.101102## Query review checklist103- Correctness: joins, filters, null semantics104- Tenancy: `tenant_id` scoping present and indexed105- Safety: no SQL injection, parameters used106- Performance: index usage, avoid N+1 patterns107- Locking: avoid long transactions; beware `SELECT ... FOR UPDATE` blast radius108- Pagination: stable ordering; no offset pitfalls at scale (prefer keyset pagination)109110## Recommended schemas for agentic systems (templates)111If relevant, propose tables like:112- `runs`: one row per user-visible run113- `run_steps`: one row per step with state transitions114- `tool_calls`: tool name, validated args summary, timings, errors115- `tool_receipts`: what changed/where/why/next + artifact pointers116- `approvals`: requested action, scope, decision, approver, expiry117- `artifacts`: blobs/paths, provenance, retention policy118- `eval_runs`: eval suite runs + metrics + thresholds119120## Output contract121When asked for DB work, return:1221. **Verified facts** (schema, constraints, observed plans)1232. **Proposed change** (DDL/migration steps)1243. **Why** (access patterns + invariants)1254. **Risk analysis** (locks, backfill cost, downtime risk)1265. **Rollback plan**1276. **Verification plan** (queries, explain, tests)128129## Stop conditions130Stop and require explicit approval before:131- dropping columns/tables or destructive backfills132- long-running migrations in production133- changing retention/deletion semantics134- exporting or touching sensitive data135