Prevent coding agents changing database conventions by recording the accepted convention and its rationale, requiring retrieval before schema work, and adding deterministic checks for objective consequences such as migration location, naming or forbidden operations. Keep judgement-based data-model choices under review.
Make the convention explicit
An agent will usually imitate nearby code, but mixed legacy patterns make that inference unreliable. Record which migration tool, ownership boundary, naming scheme, deletion policy and compatibility rules apply, together with exceptions and the reason they exist.
Retrieve before generating a migration
Schema work should begin by querying decisions about the affected tables and service boundary. The plan should cite those records and identify whether it introduces a destructive operation, changes ownership or affects backwards compatibility.
- Use the canonical migration generator and directory.
- Preserve expand-and-contract sequencing where required.
- Do not hard-delete entities covered by a retention decision.
- Name the owner for shared or cross-service data.
Enforce the objective subset
CI can inspect migration paths, filenames, forbidden statements and required metadata. It may run migrations against a clean database and test backward compatibility. It cannot prove that every new table has the right domain model or that a denormalisation is justified; those remain review questions.
Handle exceptions through decisions
Do not teach agents to silence a gate with a comment. If a migration genuinely needs an exception, record the scoped decision and its consequences. The exception then becomes reviewable authority instead of an unexplained bypass that later agents copy.