(manager: &SchemaManager<'_>, mut steps: Option<u32>)
| 358 | } |
| 359 | |
| 360 | async fn exec_up<M>(manager: &SchemaManager<'_>, mut steps: Option<u32>) -> Result<(), DbErr> |
| 361 | where |
| 362 | M: MigratorTrait + ?Sized, |
| 363 | { |
| 364 | let db = manager.get_connection(); |
| 365 | |
| 366 | M::install(db).await?; |
| 367 | |
| 368 | if let Some(steps) = steps { |
| 369 | info!("Applying {} pending migrations", steps); |
| 370 | } else { |
| 371 | info!("Applying all pending migrations"); |
| 372 | } |
| 373 | |
| 374 | let migrations = M::get_pending_migrations(db).await?.into_iter(); |
| 375 | if migrations.len() == 0 { |
| 376 | info!("No pending migrations"); |
| 377 | } |
| 378 | for Migration { migration, .. } in migrations { |
| 379 | if let Some(steps) = steps.as_mut() { |
| 380 | if steps == &0 { |
| 381 | break; |
| 382 | } |
| 383 | *steps -= 1; |
| 384 | } |
| 385 | info!("Applying migration '{}'", migration.name()); |
| 386 | migration.up(manager).await?; |
| 387 | info!("Migration '{}' has been applied", migration.name()); |
| 388 | let now = SystemTime::now() |
| 389 | .duration_since(SystemTime::UNIX_EPOCH) |
| 390 | .expect("SystemTime before UNIX EPOCH!"); |
| 391 | seaql_migrations::Entity::insert(seaql_migrations::ActiveModel { |
| 392 | version: ActiveValue::Set(migration.name().to_owned()), |
| 393 | applied_at: ActiveValue::Set(now.as_secs() as i64), |
| 394 | }) |
| 395 | .table_name(M::migration_table_name()) |
| 396 | .exec(db) |
| 397 | .await?; |
| 398 | } |
| 399 | |
| 400 | Ok(()) |
| 401 | } |
| 402 | |
| 403 | async fn exec_down<M>(manager: &SchemaManager<'_>, mut steps: Option<u32>) -> Result<(), DbErr> |
| 404 | where |
nothing calls this directly
no test coverage detected