78 lines
2.8 KiB
Rust
78 lines
2.8 KiB
Rust
pub use sea_orm_migration::prelude::*;
|
|
|
|
mod migrations;
|
|
use migrations::*;
|
|
use sea_orm_migration::sea_orm::{ConnectOptions, Database};
|
|
|
|
pub struct Migrator;
|
|
|
|
#[async_trait::async_trait]
|
|
impl MigratorTrait for Migrator {
|
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
|
vec![
|
|
Box::new(m20251011_000001_create_config_table::Migration),
|
|
Box::new(m20251011_000002_create_user_table::Migration),
|
|
Box::new(m20251011_000003_create_user_identity_table::Migration),
|
|
Box::new(m20251223_000004_create_upstream_table::Migration),
|
|
Box::new(m20251223_000005_create_upstream_target_table::Migration),
|
|
Box::new(m20260102_000006_create_proxy_table::Migration),
|
|
Box::new(m20260102_000007_create_location_table::Migration),
|
|
]
|
|
}
|
|
}
|
|
|
|
pub async fn migrate_database(db_url: &str) -> Result<(), DbErr> {
|
|
let mut opt = ConnectOptions::new(db_url);
|
|
opt.max_connections(10)
|
|
.min_connections(0)
|
|
.connect_timeout(std::time::Duration::from_secs(8))
|
|
.idle_timeout(std::time::Duration::from_secs(8))
|
|
.test_before_acquire(true)
|
|
.sqlx_logging(true)
|
|
.sqlx_logging_level(log::LevelFilter::Debug);
|
|
let db = Database::connect(opt).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
|
|
}
|