Background Tasks and CLI commands
Relevant source files
The following files were used as context for generating this wiki page:
Background tasks and Command Line Interface (CLI) commands in SeaORM Pro provide the essential infrastructure for administrative operations, environment initialization, and project maintenance. These tools allow developers to manage database schemas, populate initial datasets, and automate repetitive setup tasks through a structured task execution framework provided by the loco-rs integration.
The system primarily utilizes the sea-orm-pro-backend-cli binary to execute tasks defined within the project. These tasks range from basic data seeding for development environments to complex scaffolding operations that clean up demo entities for production use.
Sources: README.md:31-36, Cargo.toml:50-53, src/tasks/seed.rs:24-28
Data Seeding Infrastructure
The data seeding system is implemented as a Loco task named seed_data. It is designed to initialize development or demo environments by importing data from specialized TSV files. The task supports both incremental updates and full database resets via optional arguments.
Task Logic and Execution
The SeedData struct implements the Task trait, which defines the task's identity and its execution logic. When executed, it checks for a refresh argument; if set to "true", the database is reset using migrations; otherwise, migrations are simply applied to bring the schema up to date.
The workflow ensures that the database schema is always compatible with the data being seeded. Data is read from the /migration/AdventureWorks-2012-LT-Script/ directory and processed in chunks of 100 to optimize performance.
Sources: src/tasks/seed.rs:24-64, src/tasks/seed.rs:88-124
Data Encoding and Formats
The seeder handles multiple file encodings and delimiters specifically tailored for the AdventureWorks dataset. This is managed through a set of internal macros that map entities to their respective source files and encoding requirements.
| Macro | Encoding | Delimiter | Terminator |
|---|---|---|---|
seed_table_win_1252 | WINDOWS_1252 | Tab (\t) | CRLF |
seed_table_utf_16 | UTF_16LE | Tab (\t) | CRLF |
seed_table_utf_16_tilde | UTF_16LE | Tilde (~) | DOLLAR_SIGN ($) |
Sources: src/tasks/seed.rs:50-70
Maintenance and Utility Commands
Beyond standard tasks, the project provides shell scripts for structural maintenance and dependency management.
Project Scaffolding
The scaffold.sh script is used to transition a project from a demo state to a clean slate. It performs destructive operations to remove demo entities and reset configuration files.
- Migration Cleanup: Removes existing migrations and restores them from a backup (
bak) directory. - Model Reset: Deletes all model files except for the
user.rsmodel. - Configuration Truncation: Uses
sedto remove scaffold-specific blocks fromdashboard.toml. - Code Cleanup: Removes markers delimited by
// Start: Scaffold //and// End: Scaffold //across the source tree.
Sources: build_tools/scaffold.sh:4-21, README.md:104-108
Asset Management
The download_frontend.sh script manages the administrative interface assets. It automates the retrieval of the admin panel frontend from GitHub releases.
- Clears the
assets/admindirectory. - Downloads the
admin_panel.tar.gzarchive. - Extracts the archive contents with component stripping to align with the project's asset structure.
Sources: build_tools/download_frontend.sh:5-16
CLI Execution Patterns
Tasks and operations are executed using standard cargo commands or direct script execution.
| Command | Description | Source |
|---|---|---|
cargo run task seed_data | Runs the standard data seeding process. | README.md:31 |
cargo run task seed_data refresh:true | Resets the database before seeding data. | src/tasks/seed.rs:13 |
sh build_tools/scaffold.sh | Removes demo entities and resets models. | build_tools/scaffold.sh |
sea-orm-cli generate entity ... | Generates database entities (External CLI). | README.md:112 |
Sources: README.md:31-36, src/tasks/seed.rs:10-15, build_tools/scaffold.sh:1-2
Summary
Background tasks and CLI commands in SeaORM Pro facilitate a robust development lifecycle. The seed_data task provides complex data ingestion logic with support for various encodings, while auxiliary scripts like scaffold.sh and download_frontend.sh automate project initialization and cleanup. These tools ensure that developers can quickly set up, reset, or customize the admin panel environment with minimal manual intervention.