About rust-sqlx-postgres-service
rust-sqlx-postgres-service is a skill for making schema-first, compile-checked, testable changes to Rust/Postgres projects. It guides migrations, SQLx query patterns, dependency injection, transaction use, and verification.
Key features
- 01Plan schema changes before repository code
- 02Use compile-time checked SQLx queries
- 03Inject pools and transactions explicitly
- 04Apply safe migration practices
- 05Add integration tests for behavior changes
- 06Run SQLx and Cargo preflight checks
Use cases
- 01Add a Postgres schema change to a Rust service
- 02Implement repository functions with SQLx
- 03Make multi-step database operations transactional
- 04Verify migrations and SQLx metadata
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ lvtd-llc/ skills --skill rust-sqlx-postgres-serviceAfter installing, type/rust-sqlx-postgres-servicein Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
agents/openai.yamlreferences/migration-safety.mdsqlx-patterns.mdscripts/sqlx-preflight.shDetails
From the project READMERust SQLx Postgres Service
Use this skill to make Rust/Postgres changes schema-first, compile-checked, and testable. Prefer explicit migrations, injected pools, narrow repository functions, and transaction boundaries that match the business operation.
Core Workflow
- Inspect
Cargo.toml,migrations/,.sqlx/,docker-compose.yml, CI, and existing database helper modules before changing code. - Design the schema change first. Create or update a migration before writing repository code that depends on it.
- Prefer
sqlx::query!andquery_as!for compile-time checked SQL. Use dynamic SQL only when the query shape truly changes at runtime. - Inject
PgPool,PgConnection, orTransactionexplicitly. Do not create a pool inside handlers or repository functions. - Keep repository functions small and named by behavior. Return domain types or persistence DTOs instead of leaking raw rows through the app.
- Use a transaction for multi-step operations that must commit or roll back together.
- Add or update integration tests that run migrations and exercise the public behavior when the change affects API semantics.
- Run the bundled preflight script or the repository's equivalent SQLx/Cargo CI commands.
Migration Rules
Read references/migration-safety.md before changing existing tables or data.
Default migration preferences:
- Use additive changes first: new nullable columns, new tables, new indexes.
- Backfill separately from schema creation when a table may be large.
- Add
not null, uniqueness, and foreign-key constraints only after existing data satisfies them. - Name constraints and indexes deliberately when they will appear in errors or operations.
- Keep down migrations if the project uses them; otherwise document rollback expectations in the migration review.
Query Rules
Read references/sqlx-patterns.md for SQLx macro, transaction, and offline
mode details.
- Prefer bind parameters over string interpolation.
- Use
fetch_optionalfor lookup-by-key operations. - Use
executefor inserts/updates where row data is not needed. - Use
RETURNINGwhen the caller needs generated IDs or timestamps. - Check affected row counts for updates and deletes that should target exactly one row.
- Map database uniqueness conflicts to domain errors near the repository edge.
Verification
Run from the Rust project root when the standard SQLx workflow applies:
path/to/rust-sqlx-postgres-service/scripts/sqlx-preflight.sh
The script is conservative: it checks formatting and tests, inspects SQLx
migration state when the CLI and DATABASE_URL are available, verifies SQLx
offline metadata with cargo sqlx prepare --check when .sqlx/ or
DATABASE_URL is available, and only applies migrations when
RUST_SQLX_PREFLIGHT_RUN_MIGRATIONS=1 is set.
If the repository has a different CI command, use that command and explain why.
Reference Files
references/sqlx-patterns.md:query!,query_as!, pools, transactions, feature flags, and offline mode.references/migration-safety.md: safe migration sequencing and rollout checks.