MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / exec_up

Function exec_up

sea-orm-migration/src/migrator.rs:360–401  ·  view source on GitHub ↗
(manager: &SchemaManager<'_>, mut steps: Option<u32>)

Source from the content-addressed store, hash-verified

358}
359
360async fn exec_up<M>(manager: &SchemaManager<'_>, mut steps: Option<u32>) -> Result<(), DbErr>
361where
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
403async fn exec_down<M>(manager: &SchemaManager<'_>, mut steps: Option<u32>) -> Result<(), DbErr>
404where

Callers

nothing calls this directly

Calls 6

into_iterMethod · 0.80
get_connectionMethod · 0.45
upMethod · 0.45
execMethod · 0.45
table_nameMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected