Skip to main content

Module db_cli

Module db_cli 

Source
Available on non-WebAssembly only.
Expand description

rws db migrate|rollback|status|seed: the project’s migrations and seeds from the command line (18.30.0). rws db migrate|rollback|status|seed: the project’s migrations and seeds from the command line (18.30.0). rws db migrate|rollback|status|seed|schema (18.30.0, #91): the project’s migrations and seeds from the command line — the same operations, and for status / schema the same JSON, as the dev MCP server’s migrations, migrations_run, migrations_rollback_last and db_schema tools (they share dev_mcp::db).

  • Database: --database-url <url>, else DATABASE_URL, else the RWS_DB_* variables DbPool::from_env reads. URLs are sqlx’s: sqlite:app.db (?mode=rwc creates the file), postgres://…, mysql://….
  • Migrations: the migrations path of the project’s rws.app.toml (migrations/ without one), under --dir (default .); --migrations <dir> overrides it.
  • Seeds: seeds/ beside the migrations directory (migrations/ → seeds/, db/migrations/ → db/seeds/); --seeds <dir> overrides it. Every *.sql file runs, in name order, each in its own transaction, every time — see DbPool::seed. An app’s own binary can offer the same command with seeders written in Rust after the SQL files: run_with_seeders.
  • Schema: schema prints every table’s columns, primary key, indexes and foreign keys (DbPool::schema); --json as the dev MCP server’s db_schema answers it.

The rws binary has the command in every build, but it only reaches a database when built with a model-* feature (cargo install rust-web-server --features model-sqlite,model-postgres,model-mysql); otherwise it says so and exits with EXIT_USAGE.

Constants§

EXIT_FAILED
The database or a migration failed (connection, SQL error, missing .down.sql, unreadable directory): see the message.
EXIT_OK
Done.
EXIT_USAGE
Bad arguments, or a build without a database driver.

Functions§

requested
rws db … asked for: the arguments after db.
run
Run rws db <args> (the arguments after db), writing to out and err; answers the exit code (EXIT_OK, EXIT_FAILED, EXIT_USAGE).
run_with_seedersmodel-mysql or model-postgres or model-sqlite
As run, with seeders run after the SQL seed files by seed (18.30.0) — for an app’s own binary, so myapp db seed runs the seeds written in Rust too (the rws binary can’t link them):