Add CLI application with database migration and entity generation commands
- Introduced a new CLI application in the `apps/cli` directory. - Implemented commands for database migration and entity generation. - Updated `Cargo.toml` files to include necessary dependencies. - Enhanced the `justfile` to facilitate CLI command execution. - Modified workspace configuration to include the new CLI application.
This commit is contained in:
@@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod migrations;
|
||||
use migrations::*;
|
||||
use sea_orm_migration::sea_orm::Database;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -14,3 +15,49 @@ impl MigratorTrait for Migrator {
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn migrate_database(db_url: &str) -> Result<(), DbErr> {
|
||||
let db = Database::connect(db_url).await?;
|
||||
Migrator::up(&db, None).await
|
||||
}
|
||||
|
||||
pub async fn generate_entity(
|
||||
db_url: &str,
|
||||
output_dir: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
use sea_orm_cli::commands::generate::run_generate_command;
|
||||
run_generate_command(
|
||||
sea_orm_cli::GenerateSubcommands::Entity {
|
||||
compact_format: true,
|
||||
expanded_format: false,
|
||||
frontend_format: false,
|
||||
include_hidden_tables: false,
|
||||
tables: vec![],
|
||||
ignore_tables: vec!["seaql_migrations".to_string()],
|
||||
max_connections: 1,
|
||||
acquire_timeout: 30,
|
||||
output_dir: output_dir.to_string(),
|
||||
database_schema: Some("public".to_string()),
|
||||
database_url: db_url.to_string(),
|
||||
with_prelude: "all".to_string(),
|
||||
with_serde: "both".to_string(),
|
||||
serde_skip_deserializing_primary_key: false,
|
||||
serde_skip_hidden_column: false,
|
||||
with_copy_enums: true,
|
||||
date_time_crate: sea_orm_cli::DateTimeCrate::Chrono,
|
||||
lib: false,
|
||||
model_extra_derives: vec![],
|
||||
model_extra_attributes: vec![],
|
||||
enum_extra_derives: vec![],
|
||||
enum_extra_attributes: vec![],
|
||||
seaography: false,
|
||||
impl_active_model_behavior: true,
|
||||
big_integer_type: sea_orm_cli::BigIntegerType::I64,
|
||||
column_extra_derives: vec![],
|
||||
entity_format: Some("dense".to_string()),
|
||||
preserve_user_modifications: false,
|
||||
},
|
||||
false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user