mk:database
Handles data model, schema, migration, query, index and ORM work, starting from the engine the repository already runs.
| Source | .claude/skills/database/SKILL.md |
| Owner | portability |
| Runtime | portable |
| Risk | high |
mk:database owns the data layer: invariants, schema, safe evolution, query and index evidence, and the ORM data-access boundary. It finds the engine, migration tool and ORM the repository already uses before writing any syntax. There is no default engine, and if the repository does not say, the skill asks.
When not to use it
| If you need | Use |
|---|---|
| An API contract (a table is not an API type) | mk:api-design-principles |
| Service or handler code that uses the data | mk:backend-development |
| Provisioning, backups, replicas or any production effect | mk:devops |
| A security verdict | the security workflow (mk:cso) |
Usage
/mk:database [model|migration|query|index|orm|store] [description]| Argument | Reference loaded |
|---|---|
model | references/schema-design.md (entities, keys, relationships, tenancy, constraints) |
migration | references/migration-patterns.md (changing a table with data, backfills, recovery) |
query, index | references/query-optimization.md |
store, orm | None. Handled in the skill itself, only for greenfield work or when you ask to change stores |
What it does
- Discover: dependency manifest, schema, migration directory and tool, ORM config, query call sites, data tests and the active plan. Record the engine, its version and whether an ORM owns the schema.
- Classify the work as model, migration, query or index, or store and ORM selection.
- State invariants before syntax: entity and lifecycle, identity and uniqueness, tenancy and authorization boundary, retention and personal data, consistency need, access patterns and performance baseline. Unknowns stay marked unknown, and an invariant no one can state is itself a finding.
- Design in proportion to the evidence. Normalise or denormalise only with a stated reason, and choose an index from filter, join and order evidence weighed against write cost. Follow the repository's naming, key and timestamp conventions.
- Evolve safely: compatibility with the running code, locking behaviour at this size on this engine, the backfill, the signal that proves it worked, and a reverse migration or a documented forward recovery. Expand, migrate, contract fits most changes on a live table.
- Validate on a disposable database with synthetic, non-personal fixtures, then hand off with the engine evidence, invariants, migration and recovery, query and index evidence, and what remains unproven.
The skill never runs a reset, drop, backfill or migration against a live database. It prepares the change and hands execution to mk:ship or a person.
For store and ORM choice, decide from the invariants and what the team can operate, since a second store adds a second operational burden. An ORM is the access boundary, not the data model, and the database should enforce the invariants it can.
Security
Never build a query by string interpolation or template concatenation. Use the driver or ORM parameter mechanism. Never log, print or copy personal data while investigating. Describe a row by its shape.
Gotchas
Each depends on the engine in use.
- A
NOT NULLcolumn with no default can rewrite the table. On PostgreSQL before 12 it takes an exclusive lock. Add it nullable, backfill in batches, then add the constraint. - A plain index build blocks writes on PostgreSQL. The concurrent form cannot run in a transaction block and can leave an invalid index if it fails.
- Cascading deletes remove child rows with no error. Audit cascading foreign keys before a bulk delete.
- The analysing form of
EXPLAINruns the statement. Never use it on anINSERT,UPDATEorDELETEoutside a transaction you will roll back. - Pool exhaustion looks like a slow query. Check for connections held past their work first.
- Read-committed allows non-repeatable reads. Financial and inventory logic needs a stricter level chosen on purpose.
- A reverse migration that silently discards data is worse than saying the change is forward-only and naming the corrective change.
- SQLite serialises writers and rewrites tables for most
ALTERs. That is rarely a reason to propose another engine.
mk:build-fix
Triages build, compile and type errors by language and fixability, applies minimal fixes, and retries up to three times.
mk:devops
Designs and prepares infrastructure, container, pipeline and runtime-configuration changes with rollback in mind. It never runs the production step and never reads a secret.