database

Enforces compile-time checked sqlx queries and offline cache workflows for PostgreSQL development.

1|1|Updated May 14, 2026
One-click install
npx skills add https://github.com/alexmohr/assimilate --skill database-alexmohr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database
Source: https://github.com/alexmohr/assimilate/tree/main/skills/database
Command: npx skills add https://github.com/alexmohr/assimilate --skill database-alexmohr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It prevents runtime SQL failures in a Rust sqlx codebase by enforcing compile-time checked queries, keeping the offline query cache in sync with migrations, and ensuring database integration tests always run against real PostgreSQL in CI. ## Core Features & Use Cases - Compile-time query enforcement: Mandates query!, query_as!, and query_scalar! macros while banning runtime sqlx constructors, verified by a CI script and pre-commit hook. - Offline cache management: Defines the workflow for regenerating and verifying the .sqlx/ directory with cargo sqlx prepare after any query or migration change. - Integration test discipline: Requires PostgreSQL service containers in CI and isolated per-test databases via #[sqlx::test]. - Use Case: When adding a migration or editing a query in crates/server/tests/db_queries.rs, follow the workflow to run tests locally, regenerate the sqlx cache, and pass the CI freshness check. ## Quick Start Ask the assistant to add a new compile-time checked sqlx query and migration, then regenerate the offline cache and run the database integration tests.

Frequently Asked Questions about database

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new sqlx query in a Rust project?

Write the query using the compile-time checked macros query!, query_as!, or query_scalar! rather than runtime constructors. Then regenerate the offline cache with cargo sqlx prepare --workspace and commit the updated .sqlx directory alongside the change.

How do I run sqlx integration tests against PostgreSQL?

Start a PostgreSQL server, set DATABASE_URL to a user with CREATEDB privilege, and run cargo test -p server --test db_queries. Tests use #[sqlx::test] which creates an isolated temporary database with all migrations applied per test.

Why does cargo sqlx prepare --check fail in CI?

The check fails when the committed .sqlx offline cache is stale relative to the current queries or migrations. Fix it by running cargo sqlx prepare --workspace against a live database and committing the regenerated cache.

Can I use sqlx::query runtime constructors instead of macros?

No, runtime constructors like sqlx::query are banned because schema changes would fail silently at runtime instead of at compile time. This is enforced by a CI script and a pre-commit hook that reject raw sqlx queries.

Why do database tests fail with duplicate key errors?

Failures occur when tests assume specific auto-increment IDs, since migrations seed roles like admin, operator, and viewer. Use unique names for test data instead of relying on fixed IDs to avoid conflicts.