Rust Database
Rule
Make persistence explicit, transactional, context-aware, and isolated from real mutable
systems. Prefer explicit SQL and typed boundaries before ORM-style abstractions.
Hard Stops
Stop before:
- Touching production or developer databases without explicit approval and backup/safety
plan.
- Running destructive migrations, changing schema, or changing data retention semantics
without rollback and compatibility discussion.
- Adding SQLx, Diesel, SeaORM, migration tools, or containers without approval.
- Using real credentials or committing generated secrets.
Defaults
- Prefer SQLx for async SQL in Tokio services when compile-time query checking or explicit
SQL fits.
- Use SQLx migrations for straightforward app-owned schemas.
- Use Diesel only when a synchronous, compile-time query-builder/ORM model is explicitly
desired.
- Use SeaORM only for dynamic/entity-driven CRUD services where that tradeoff is approved.
- Make transactions explicit and keep their scope small.
- Pass pools/connections through application state; avoid global pools.
- Map database errors to domain errors at the data boundary.
- Configure pool size, acquisition timeout, and statement timeouts intentionally.
Testing
Use isolated temporary databases, test schemas, transaction rollbacks, or approved
testcontainers when real database behavior matters. Never point tests at production or a
developer's default database by accident. Test migrations, constraints, not-found behavior,
unique conflicts, rollback, and serialization/deserialization edge cases.
Workflow
- Define schema, migrations, queries, transaction boundaries, indexes, and failure behavior.
- Choose SQLx, Diesel, SeaORM, or existing project access based on approved needs.
- Implement data access behind small stores/repositories consumed by services.
- Add isolated tests and fixtures.
- Run migrations/tests, full tests, Clippy, and
just check.
Antipatterns
- String-concatenated SQL with untrusted input.
- Auto-running destructive migrations on every production startup.
- Hiding large workflows in implicit transactions.
- Treating generated ORM entities as domain models by default.
- Tests that require machine-local database state.
Completion
Report schema/query changes, transaction model, tool choices, test database approach,
commands, and safety boundaries.
Source: nyquistwilder/personal-pi — distributed by TomeVault.
1---2name: rust-database3description: Greenfield Rust database workflow for SQLx or project-selected access, migrations, transactions, pooling, query correctness, test databases, and isolation from real data. Use when this capability is needed.4---56# Rust Database78## Rule910Make persistence explicit, transactional, context-aware, and isolated from real mutable11systems. Prefer explicit SQL and typed boundaries before ORM-style abstractions.1213## Hard Stops1415Stop before:1617- Touching production or developer databases without explicit approval and backup/safety18 plan.19- Running destructive migrations, changing schema, or changing data retention semantics20 without rollback and compatibility discussion.21- Adding SQLx, Diesel, SeaORM, migration tools, or containers without approval.22- Using real credentials or committing generated secrets.2324## Defaults2526- Prefer SQLx for async SQL in Tokio services when compile-time query checking or explicit27 SQL fits.28- Use SQLx migrations for straightforward app-owned schemas.29- Use Diesel only when a synchronous, compile-time query-builder/ORM model is explicitly30 desired.31- Use SeaORM only for dynamic/entity-driven CRUD services where that tradeoff is approved.32- Make transactions explicit and keep their scope small.33- Pass pools/connections through application state; avoid global pools.34- Map database errors to domain errors at the data boundary.35- Configure pool size, acquisition timeout, and statement timeouts intentionally.3637## Testing3839Use isolated temporary databases, test schemas, transaction rollbacks, or approved40`testcontainers` when real database behavior matters. Never point tests at production or a41developer's default database by accident. Test migrations, constraints, not-found behavior,42unique conflicts, rollback, and serialization/deserialization edge cases.4344## Workflow45461. Define schema, migrations, queries, transaction boundaries, indexes, and failure behavior.472. Choose SQLx, Diesel, SeaORM, or existing project access based on approved needs.483. Implement data access behind small stores/repositories consumed by services.494. Add isolated tests and fixtures.505. Run migrations/tests, full tests, Clippy, and `just check`.5152## Antipatterns5354- String-concatenated SQL with untrusted input.55- Auto-running destructive migrations on every production startup.56- Hiding large workflows in implicit transactions.57- Treating generated ORM entities as domain models by default.58- Tests that require machine-local database state.5960## Completion6162Report schema/query changes, transaction model, tool choices, test database approach,63commands, and safety boundaries.6465---66> Source: [nyquistwilder/personal-pi](https://github.com/nyquistwilder/personal-pi) — distributed by [TomeVault](https://tomevault.io).67<!-- tomevault:4.0:skill_md:2026-06-16 -->