Deployment Guidelines
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The deployment of a SeaORM Pro based application involves configuring a Rust-based backend (typically using Loco.rs or Axum), setting up a supported database backend, and integrating the pre-built admin panel assets. The project is designed to be highly configurable through TOML files and environment variables, allowing for rapid movement from a demo environment to a customized production-ready system.
Sources: README.md:1-85, examples/axum_example/api/src/lib.rs:35-100
Environment Configuration
The application relies on a .env file to manage environment-specific variables such as database connection strings and server network settings.
Database Backend Setup
Before running the application, the DATABASE_URL must be defined. SeaORM Pro supports multiple database backends including SQLite, MySQL, and PostgreSQL. The specific backend must be enabled as a feature in Cargo.toml.
| Variable | Description | Example Value |
|---|---|---|
DATABASE_URL | Connection string for the database | postgres://root:root@localhost/db |
HOST | Server host address | 0.0.0.0 |
PORT | Server port number | 8086 |
Sources: README.md:10-23, Cargo.toml:43-47, examples/axum_example/api/src/lib.rs:43-47
Server Initialization Flow
The following diagram illustrates the startup sequence of the backend server, including environment loading and database connection.
The server initialization ensures that the database schema is up-to-date via migrations before accepting requests.
Sources: examples/axum_example/api/src/lib.rs:35-102
Database Migrations and Seeding
Deployments require the execution of migrations to establish the schema and optionally seed the database with initial data.
Migration CLI Commands
The migrator allows for granular control over the database schema state.
| Command | Action |
|---|---|
cargo run | Apply all pending migrations |
cargo run -- up -n <N> | Apply the next N migrations |
cargo run -- down | Rollback the last migration |
cargo run -- refresh | Rollback all and re-apply all migrations |
cargo run -- status | Check current migration status |
Sources: migration/README.md:1-40
Data Seeding Task
The project includes a custom task for seeding data from TSV/CSV files. This is typically used for initializing demo or development environments. The task can be run using cargo run task seed_data. If the refresh:true argument is provided, the database is reset before seeding.
// Logic for seeding from CSV/TSV files
let file = std::fs::OpenOptions::new().read(true).open(format!(
"{}/migration/AdventureWorks-2012-LT-Script/{}",
env!("CARGO_MANIFEST_DIR"),
csv
))?;
Sources: src/tasks/seed.rs:10-30, src/tasks/seed.rs:90-100
Admin Panel Assets
The admin panel is a frontend application whose assets must be downloaded and served by the backend.
- Download Assets: Use the provided script
sh build_tools/download_frontend.shto fetch the admin panel build. - Asset Storage: Assets are typically stored in a directory named
assets/admin. - Static Serving: The backend must be configured to serve these files. In Axum-based setups, this is handled via
ServeDirandServeFileto support Single Page Application (SPA) routing.
Scaffolding for Customization
To transition from the demo to a custom project, the scaffolding script removes demo-specific entities and configurations.
- Execution: Run
sh build_tools/scaffold.sh. - Actions:
- Removes demo migration files.
- Clears
pro_admin/raw_tablesandpro_admin/composite_tablesTOML files. - Resets the
src/modelsdirectory.
- Re-generation: After scaffolding, users should generate their own entities using
sea-orm-cli generate entity -o src/models --seaography.
Sources: build_tools/scaffold.sh:1-20, README.md:65-75
Security and Authentication
The deployment uses a token-based authentication system for the admin panel.
Credentials and Auth
In the demo configuration, hardcoded credentials and a demo JWT token are utilized. For production deployment, these must be replaced with a secure user management system and environment-stored secrets.
| Parameter | Demo Value |
|---|---|
| Admin Email | admin@sea-ql.org |
| Admin Password | demo@sea-ql.org |
| Token Header | AUTHORIZATION |
Sources: examples/axum_example/api/src/lib.rs:215-220, examples/axum_example/api/src/lib.rs:245-255
Summary
Deploying SeaORM Pro involves configuring the database via environment variables, running migrations through the CLI, and ensuring the admin frontend assets are correctly served. Developers can utilize the scaffolding tools to strip demo data and regenerate entities for their specific use cases, while managing administrative access through configuration files like pro_admin/config.toml.