Database guardrails
Treat database work as a gated design conversation. A request to add persistence
or change a model is not permission to connect to, inspect, or mutate a live
database.
Hard stop before database access
Unless the user explicitly authorizes the exact target, operation, and scope:
- Do not open a database connection, issue a query, inspect a live database,
run a migration, seed data, reset or dump a database, or run tests that write
to a real database.
- Do not infer permission from a general request such as “add a database” or
“fix the data.” Keep the work at repository code, schema files, migration
history, documentation, or synthetic/disposable fixtures.
- If the environment, owner, data sensitivity, or allowed side effects are
unclear, stop and ask. Say explicitly that no database action has been taken.
Converse before designing the schema
Before proposing tables or columns, make the behavior concrete and ask about:
- The one user-visible or service-level use case being supported first.
- The target database and environment, who owns it, and whether this is a
fresh install, an upgrade, or a repair.
- Existing schema and migration ownership, data-retention requirements, and
compatibility with current callers.
- Identity, nullability, units and precision, time zones, authorization,
concurrency, transaction boundaries, and recovery expectations.
- Whether any backfill, data rewrite, destructive change, or downtime is
actually authorized.
Explain why the current schema or persistence boundary is insufficient before
proposing a change. Then show the smallest design: only the necessary tables,
columns, types, defaults, relationships, and constraints. Start with one
bounded workflow and increase the model only when a concrete requirement or
measured failure justifies it.
Use constraints to protect real invariants: primary keys, foreign keys,
uniqueness, nullability, checks, and valid state transitions. Do not add
speculative audit/event tables, soft-delete flags, tenants, generic entity-value
models, JSON escape hatches, or lookup tables merely because they might be
useful later.
Index only for a reason
Every index must have a named query, join, uniqueness rule, ordering/filter
path, or measured performance problem behind it. Record the reason and expected
selectivity. Do not index every column, every foreign key automatically, or
duplicate an existing prefix/covering index. Re-check write cost, storage,
cardinality, and the query plan before keeping an index that is not required by
a constraint or demonstrated access path.
Make changes programmatically and incrementally
- If the project has a migration system, use its programmatic, versioned,
reviewed migration mechanism and the repository's normal command to run it.
- If the project does not support that mechanism, write a scoped migration
program/file and its dry-run, recovery, and execution instructions into the
project first. Do not improvise SQL in a terminal or GUI and do not execute
an unreviewed artifact from chat.
- Keep migrations separate from application startup. Never silently create,
reset, seed, or repair schema on boot, and never edit an already-applied
migration; add a new migration instead.
- Preserve existing data and relationships. Plan transaction boundaries,
locking, retries, idempotency, backfills, precision, and rollback before an
authorized run. Prefer additive, reversible steps and expand later in a
separate change.
Verify and report
Before an authorized run, verify the exact target, backup/recovery path, and
the disposable fresh-install and upgrade tests. Afterward, report the commit,
artifact, target, changed tables/columns/constraints/indexes, checks run, and
rollback path. Keep the response structured as: known facts, minimal proposal,
open questions, migration artifact, approval needed, and database actions taken.
1---2name: database-guardrails3description: Plans database-backed changes with an ask-first safety gate, minimal schema growth, programmatic versioned migrations, and evidence-based indexes. Use for database modeling, schema changes, migrations, data repair, or database performance work; do not access or change a database by default.4license: MIT5---67# Database guardrails89Treat database work as a gated design conversation. A request to add persistence10or change a model is not permission to connect to, inspect, or mutate a live11database.1213## Hard stop before database access1415Unless the user explicitly authorizes the exact target, operation, and scope:1617- Do not open a database connection, issue a query, inspect a live database,18 run a migration, seed data, reset or dump a database, or run tests that write19 to a real database.20- Do not infer permission from a general request such as “add a database” or21 “fix the data.” Keep the work at repository code, schema files, migration22 history, documentation, or synthetic/disposable fixtures.23- If the environment, owner, data sensitivity, or allowed side effects are24 unclear, stop and ask. Say explicitly that no database action has been taken.2526## Converse before designing the schema2728Before proposing tables or columns, make the behavior concrete and ask about:29301. The one user-visible or service-level use case being supported first.312. The target database and environment, who owns it, and whether this is a32 fresh install, an upgrade, or a repair.333. Existing schema and migration ownership, data-retention requirements, and34 compatibility with current callers.354. Identity, nullability, units and precision, time zones, authorization,36 concurrency, transaction boundaries, and recovery expectations.375. Whether any backfill, data rewrite, destructive change, or downtime is38 actually authorized.3940Explain why the current schema or persistence boundary is insufficient before41proposing a change. Then show the smallest design: only the necessary tables,42columns, types, defaults, relationships, and constraints. Start with one43bounded workflow and increase the model only when a concrete requirement or44measured failure justifies it.4546Use constraints to protect real invariants: primary keys, foreign keys,47uniqueness, nullability, checks, and valid state transitions. Do not add48speculative audit/event tables, soft-delete flags, tenants, generic entity-value49models, JSON escape hatches, or lookup tables merely because they might be50useful later.5152## Index only for a reason5354Every index must have a named query, join, uniqueness rule, ordering/filter55path, or measured performance problem behind it. Record the reason and expected56selectivity. Do not index every column, every foreign key automatically, or57duplicate an existing prefix/covering index. Re-check write cost, storage,58cardinality, and the query plan before keeping an index that is not required by59a constraint or demonstrated access path.6061## Make changes programmatically and incrementally6263- If the project has a migration system, use its programmatic, versioned,64 reviewed migration mechanism and the repository's normal command to run it.65- If the project does not support that mechanism, write a scoped migration66 program/file and its dry-run, recovery, and execution instructions into the67 project first. Do not improvise SQL in a terminal or GUI and do not execute68 an unreviewed artifact from chat.69- Keep migrations separate from application startup. Never silently create,70 reset, seed, or repair schema on boot, and never edit an already-applied71 migration; add a new migration instead.72- Preserve existing data and relationships. Plan transaction boundaries,73 locking, retries, idempotency, backfills, precision, and rollback before an74 authorized run. Prefer additive, reversible steps and expand later in a75 separate change.7677## Verify and report7879Before an authorized run, verify the exact target, backup/recovery path, and80the disposable fresh-install and upgrade tests. Afterward, report the commit,81artifact, target, changed tables/columns/constraints/indexes, checks run, and82rollback path. Keep the response structured as: known facts, minimal proposal,83open questions, migration artifact, approval needed, and database actions taken.