Complete reference for all RustAuth CLI commands.
- Overview
- Cargo Commands
- Migration Commands
- Scaffolding Commands
- User Management
- Development Commands
- Database Commands
- Examples
- Troubleshooting
RustAuth provides CLI commands through both standard Cargo tooling and custom binaries. Commands are available via:
# Cargo shorthand (via alias in Cargo.toml)
cargo <command>
# Or explicit binary
cargo run --bin <command> -- <args>Build:
# Development build (unoptimized, fast compilation)
cargo build
# Release build (optimized, slow compilation, fast execution)
cargo build --release
# Check for errors (no artifact generation)
cargo checkCode Quality:
# Format code
cargo fmt
# Format check
cargo fmt --check
# Lint with Clippy
cargo clippy
# Lint strict (all warnings)
cargo clippy -- -D warnings
# Auto-fix issues
cargo clippy --fixTesting:
# Run all tests
cargo test
# Run test in release mode
cargo test --release
# Run specific test
cargo test test_login
# Run with output
cargo test -- --nocapture
# Run in parallel
cargo test -- --test-threads=4Documentation:
# Generate and open docs
cargo doc --open
# Generate without opening
cargo doc
# For specific crate
cargo doc --package sqlx --openApply all pending database migrations.
# Apply all pending migrations
cargo run --bin migrate
# Apply with verbose output
RUST_LOG=debug cargo run --bin migrateWhat it does:
- Reads migration files from
migrations/directory - Applies pending migrations in order
- Updates
_sqlx_migrationstable - Returns error if migration fails
Output:
✓ Running migration 20260414110602_auto
✓ Running migration 20260414115951_auto
All migrations completed successfully
Auto-detect model changes and generate SQL migrations.
# Generate migration with default label "auto"
cargo run --bin makemigrations
# Generate with custom label
cargo makemigrations add_user_preferences
# Force regeneration
cargo makemigrations --forceFeatures:
- ✅ Auto-detects models in
src/apps/*/models.rs - ✅ Analyzes model directives (@schema, @table, @unique, @index)
- ✅ Generates both
up.sqlanddown.sql - ✅ Creates rollback script
- ✅ Validates relationships
Generated Files:
migrations/
├── 20260414110602_auto/
│ ├── up.sql # Forward migration
│ └── down.sql # Rollback script
Model Directives:
// @schema <name> - PostgreSQL schema
// @table <name> - Table name
// @unique - Unique constraint on field
// @unique columns=c1,c2 - Multi-column unique
// @index - Index on field
// @default <value> - Default value
// @references schema.table - Foreign key referenceDisplay migration status and history.
# Show all migrations
cargo run --bin showmigrations
# With verbose output
RUST_LOG=debug cargo run --bin showmigrationsOutput Format:
[APPLIED] 20260414110602_auto (2024-04-14 11:06:02)
[APPLIED] 20260414115951_auto (2024-04-14 11:59:51)
[PENDING] 20260414125000_example
Generate new app with all required files and configuration.
# Create basic app
cargo startapp products
# Create with custom schema
cargo startapp products --schema catalog
# Create with multiple schemas
cargo startapp products --schema catalog --schema inventoryGenerated Structure:
src/apps/products/
├── mod.rs # Module exports & routes
├── models.rs # Database models
├── schemas.rs # Request/response DTOs
├── handlers.rs # HTTP endpoint handlers
├── admin_config.rs # Admin panel metadata
└── admin_registry.rs # Admin registration
Generated mod.rs:
pub mod models;
pub mod schemas;
pub mod handlers;
pub mod admin_config;
pub mod admin_registry;
use axum::Router;
use crate::state::AppState;
pub fn router() -> Router<AppState> {
Router::new()
.route("/", post(handlers::create))
.route("/", get(handlers::list))
.route("/:id", get(handlers::get))
.route("/:id", put(handlers::update))
.route("/:id", delete(handlers::delete))
}What You Need To Do:
- Define models in
models.rs - Define DTOs in
schemas.rs - Implement handlers in
handlers.rs - Run
cargo makemigrationsto generate migration - Add routes to parent
mod.rsif needed
Create a superuser account interactively.
# Create superuser (interactive)
cargo run --bin createsuperuser
# With predefined values (non-interactive)
cargo run --bin createsuperuser -- \
--email admin@example.com \
--password "SecurePass123!" \
--name "Admin User"Prompts:
Email: admin@example.com
Password: ••••••••••••
Full Name: Admin User
Creates User With:
- is_superuser = true
- is_active = true
- email_verified = true
Open interactive shell for database queries.
# Open shell
cargo run --bin shell
# Example interactive session:
# rustauth> SELECT * FROM user.users LIMIT 1;
# (returns SQL results)
# rustauth> CREATE TABLE ...;Open native psql shell with configured database connection.
# Open psql
cargo run --bin dbshell
# Equivalent to:
# psql postgres://rustauth:password@localhost:5432/auth_devInspect database schema and statistics.
# Inspect database
cargo run --bin inspectdb
# Output includes:
# - All tables and columns
# - Data types
# - Constraints
# - Indexes
# - Table sizesInitialize Fresh Database:
# 1. Drop old database (development only)
dropdb auth_dev
# 2. Create new database
createdb auth_dev
# 3. Apply all migrations
cargo run --bin migrate
# 4. Create superuser (optional)
cargo run --bin createsuperuserBackup Database:
# SQL dump
pg_dump auth_dev > backup.sql
# Compressed dump
pg_dump -Fc auth_dev > backup.dumpRestore Database:
# From SQL file
psql auth_dev < backup.sql
# From compressed dump
pg_restore -d auth_dev backup.dumpRun project tests with database setup.
# Run all tests
cargo run --bin tests
# Run specific test
cargo run --bin tests -- test_name
# With logging
RUST_LOG=debug cargo run --bin tests# 1. Clone repository
git clone https://github.com/yourname/rustauth.git
cd rustauth
# 2. Install dependencies
cargo build
# 3. Initialize database
cargo run --bin migrate
# 4. Create superuser
cargo run --bin createsuperuser
# 5. Start development server
cargo run
# 6. View API docs
# Open http://localhost:8000/docs# 1. Scaffold new app
cargo startapp products
# 2. Edit generated files
# - src/apps/products/models.rs
# - src/apps/products/handlers.rs
# - etc.
# 3. Generate migration from models
cargo makemigrations add_products_table
# 4. Review generated migration
cat migrations/*_add_products_table/up.sql
# 5. Apply migration
cargo run --bin migrate
# 6. Test the app
cargo test
# 7. Start server
cargo run# Check migration status
cargo run --bin showmigrations
# Inspect database
cargo run --bin inspectdb
# Open shell for manual SQL
cargo run --bin shell
# View raw SQL dump
pg_dump auth_dev --schema-only | lessAdd to .bashrc or .zshrc for convenience:
# Quick commands
alias rustauth-build='cargo build'
alias rustauth-run='cargo run'
alias rustauth-test='cargo test'
alias rustauth-fmt='cargo fmt && cargo clippy'
alias rustauth-migrate='cargo run --bin migrate'
alias rustauth-migrations='cargo run --bin showmigrations'
alias rustauth-startapp='cargo run --bin startapp'
alias rustauth-shell='cargo run --bin shell'
alias rustauth-db='cargo run --bin dbshell'
# Load in shell
source ~/.bashrcThen use:
rustauth-run
rustauth-migrate
rustauth-startapp myapp# Make sure you're in project root
pwd # Should be .../rustauth
# Check Cargo.toml exists
ls Cargo.toml
# Build may not have compiled the binary
cargo build
# Try with explicit path
cargo run --bin migrate# Check migration status
cargo run --bin showmigrations
# Check specific failure
RUST_LOG=debug cargo run --bin migrate
# Inspect database state
cargo run --bin shell
# SELECT * FROM _sqlx_migrations;# Verify connection string
echo $DATABASE_URL
# Test direct connection
psql $DATABASE_URL -c "SELECT 1"
# Check if PostgreSQL is running
sudo systemctl status postgresql
# Restart PostgreSQL
sudo systemctl restart postgresql- setup.md - Initial setup
- development.md - Development workflow
- DATABASE.md - Database schema
- TROUBLESHOOTING.md - Common issues
Last Updated: April 2024
// @index columns=col1,col2- Multi-column index// @default <value>- Default value// @nullable- Force nullable// @required- Force NOT NULL// @sql_type <type>- Override SQL type// @validate <validator>- Field validator// @references schema.table- Foreign key reference
Reserved Keyword Handling: The command automatically quotes PostgreSQL reserved keywords:
user→"user"order→"order"group→"group"- And 150+ more keywords
Applies, rolls back, or targets specific migration states.
cargo migrate # Apply all pending migrations
cargo migrate status # Show migration status
cargo migrate --fake-initial # Mark first migration applied (no SQL)
cargo migrate <name> # Move to specific migration
cargo migrate <name> --fake # Mark migration applied (no SQL)Features:
- ✅ Automatic migration ordering by timestamp
- ✅ Risk detection (DROP TABLE, DROP COLUMN, etc.)
- ✅ SQL preview before execution
- ✅ Forward and backward migration support
- ✅ Module-specific migration targeting
- ✅ Transaction-safe execution
Example:
# Apply all pending migrations
cargo migrate
# Show status
cargo migrate status
# Target specific migration
cargo migrate add_users_table
# Fake apply for testing
cargo migrate add_users_table --fakeMulti-phase validation system that checks database, code structure, imports/exports, and compilation.
cargo tests # Run all validation phases
cargo tests --no-db # Skip database checks
cargo tests --no-compile # Skip compilation check
cargo tests -v # Verbose outputValidation Phases:
- ✅ Checks migration status
- ✅ Validates database schema exists
- ✅ Verifies model-schema consistency
- ✅ Checks @schema and @table directives
- ✅ Lists all schemas and tables
- ✅ Verifies required files exist (mod.rs, models.rs, schemas.rs, handlers.rs, etc.)
- ✅ Checks handler functions are present
- ✅ Validates request/response types in schemas
- ✅ Verifies model derive macros (sqlx::FromRow, Serialize)
- ✅ Checks declare_model_table! macro usage
- ✅ Validates module declarations in mod.rs
- ✅ Checks routes() function exists
- ✅ Verifies admin registry wiring
- ✅ Confirms app is registered in apps/mod.rs
- ✅ Validates route merging
- ✅ Checks admin registry calls
- ✅ Verifies OpenAPI documentation setup
- ✅ Runs
cargo check - ✅ Reports compilation errors
- ✅ Ensures project builds successfully
Example Output:
Phase 1: Database & Schema Validation
─────────────────────────────────────────────
1.1 Checking migration status...
✓ All migrations applied (1 total)
1.2 Validating database schema...
✓ Found 2 schema(s): blogs, user
• Schema 'blogs': 2 table(s)
- blog_posts
- comments
• Schema 'user': 10 table(s)
- users
- refresh_tokens
...
1.3 Checking model-schema consistency...
✓ All models have proper schema directives
✓ Phase 1 passed: Database & Schema
Phase 2: Code Structure Validation
...
Phase 3: Import/Export Validation
...
Phase 4: Compilation Check
...
═══════════════════════════════════════
✓ All test phases passed successfully!
═══════════════════════════════════════
Lists all migrations with their applied status.
cargo showmigrationsFeatures:
- ✅ Shows all migrations in order
- ✅ Displays applied/pending status
- ✅ Shows which modules each migration affects
- ✅ Shows application timestamps
Opens a PostgreSQL shell connected to your database.
cargo dbshell-
Create a new app:
cargo startapp products
-
Define models in
src/apps/products/models.rs:// @schema products // @table products #[derive(Debug, Serialize, Deserialize, sqlx::FromRow, ToSchema)] pub struct Product { pub id: Uuid, pub name: String, pub price: f64, pub created_at: DateTime<Utc>, } crate::declare_model_table!(Product, "products", "products");
-
Implement handlers in
src/apps/products/handlers.rs:pub async fn list_products(...) -> Result<impl IntoResponse, AppError> { // Implementation }
-
Wire routes in
src/apps/products/mod.rs:pub fn routes() -> Router<AppState> { Router::new() .route("/api/v1/products", get(handlers::list_products)) }
-
Validate your work:
cargo tests -v
-
Generate migration:
cargo makemigrations add_products
-
Apply migration:
cargo migrate
-
Run server:
cargo run
All commands work together seamlessly:
startapp→ Auto-registers modules, routes, and adminmakemigrations→ Auto-discovers models from all appsmigrate→ Auto-applies migrations in ordertests→ Auto-validates everything end-to-end
No manual wiring required!
The system automatically quotes PostgreSQL reserved keywords in:
- Schema names
- Table names
- Column names (when used in ALTER statements)
- Foreign key references
This prevents syntax errors when using common names like user, order, group, etc.
150+ keywords handled, including:
user,order,group,select,from,wheretable,index,key,primary,foreignschema,database,role,grant,revoke- And many more...
Solution: This is now automatically fixed. The system quotes reserved keywords.
Solution: Ensure you have:
// @schema <name>directive at the top of models.rs// @table <name>directive before each structcrate::declare_model_table!()macro call for each model
Solution: Run cargo startapp <appname> again to repair the integration, or manually check:
src/apps/mod.rshaspub mod <appname>;src/apps/mod.rshas.merge(<appname>::routes())src/admin/registry.rshas<appname>::admin_registry::register(builder);
Solution: Check that:
- All required files exist in your app directory
- Module declarations are present in mod.rs
- Routes are properly merged
- Admin registry is called
- Always run
cargo tests -vafter making changes - Use meaningful migration labels (e.g.,
add_user_profiles) - Review generated SQL before applying migrations
- Commit migrations alongside
.schema_state.json - Use directives liberally (@index, @unique, @references, etc.)
- Keep handlers separate from models and schemas
- Test with
--no-dbflag when database is unavailable
# Only apply migrations for a specific module
cargo migrate user --fake# Rollback to a specific migration
cargo migrate initial_schema# See detailed validation output
cargo tests -v
# Skip database checks (faster)
cargo tests --no-db -v# Create app with different PostgreSQL schema
cargo startapp orders --schema ecommerceRustAuth provides a complete, integrated development workflow:
- No third-party tools - Everything is built-in
- Automatic detection - Models, routes, and admin are auto-wired
- Comprehensive validation - 4-phase testing ensures correctness
- Reserved keyword safety - Automatic quoting prevents SQL errors
- Clear documentation - Step-by-step guidance at every stage
Start building with:
cargo startapp myapp
cargo tests -v
cargo makemigrations
cargo migrate
cargo run