sqlx-cli
$ sqlx Official Med Risksqlx-cli (sqlx / cargo sqlx) manages databases (sqlx database create/setup), timestamped or reversible SQL migrations (sqlx migrate run/info/revert), and sqlx prepare to cache query metadata in .sqlx/ so Rust projects compile offline with SQLX_OFFLINE=true.
brew install sqlx-cli sqlx inspects local Rust crates (cargo sqlx prepare) and ./migrations directories directly; MCP cannot replace Cargo build-time metadata generation.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Fully non-interactive with DATABASE_URL/.env support and prepare --check verification mode, though output is plain text rather than --json.
- Non-interactive
migrateandprepare --checkcommands; no--jsonflag
Verifies migration SHA-384 checksums, supports prepare --check dry verification and migrate run --dry-run (where supported), though database drop/reset are destructive.
- Checksum validation and
--checkverification;database droprequires-yor confirmation
Installable via brew install sqlx-cli and cargo install sqlx-cli across macOS, Linux, and Windows (Cargo build allows feature trimming).
- Available via Homebrew and
cargo install sqlx-cli
Indispensable for Rust SQLx projects, combining DB lifecycle, migrations, and offline compile-time SQL verification.
- Unifies
database,migrate, and offlineprepareworkflows
Official launchbadge/sqlx crate dual-licensed under MIT OR Apache-2.0.
- Official
launchbadge/sqlxrepository
Clear CLI README in launchbadge/sqlx/sqlx-cli and Clap --help.
- Official README and
--helpoutput
Security, Auth & Guardrails
Reads DATABASE_URL from the environment or a local .env file (or --database-url <URL>).
100% free under dual MIT / Apache-2.0 license.
# sqlx-cli Agent Rules - Always run `sqlx migrate info` before `sqlx migrate run` or `sqlx migrate revert`. - Use `cargo sqlx prepare --check --workspace` in CI/verification loops before regenerating `.sqlx/`. - NEVER run `sqlx database drop` or `sqlx database reset` without explicit user confirmation.
Agent-Ready Command Recipes
Safe Read-Only Queries
sqlx migrate info
Lists every migration in ./migrations along with its applied or pending state against DATABASE_URL.
.sqlx/ query cache is up to date cargo sqlx prepare --check --workspace
Verifies in CI/agent checks that .sqlx/ query metadata matches current Rust SQL macros without modifying files.
Controlled Writes & Previews
sqlx migrate run
Applies all pending SQL migrations against DATABASE_URL and records checksums in _sqlx_migrations.
Strengths for Agents
- +
cargo sqlx prepare --checkverifies offline.sqlx/query metadata cleanly in CI. - + Automatic
.envDATABASE_URLloading and SHA-384 migration checksum tracking.
Caveats & Pitfalls
- ! Lacks a
--jsonoutput flag forsqlx migrate info. - !
cargo install sqlx-clicompiles Rust crates from source unless installed via Homebrew/binstall.