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 (18.30.0, #91): the project’s migrations and seeds from the command line — the same operations, and for status the same JSON, as the dev MCP server’s migrations, migrations_run and migrations_rollback_last 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.

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).