pub trait MigrationTrait: MigrationName + Send + Sync {
    fn up<'life0, 'life1, 'async_trait>(
        &'life0 self,
        manager: &'life1 SchemaManager<'_>
    ) -> Pin<Box<dyn Future<Output = Result<(), DbErr>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
; fn down<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _manager: &'life1 SchemaManager<'_>
    ) -> Pin<Box<dyn Future<Output = Result<(), DbErr>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
, { ... } }
Expand description

The migration definition

Required Methods§

Define actions to perform when applying the migration

Provided Methods§

Define actions to perform when rolling back the migration

Examples found in repository?
src/migrator.rs (line 300)
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    async fn down(db: &DbConn, mut steps: Option<u32>) -> Result<(), DbErr> {
        Self::install(db).await?;
        let manager = SchemaManager::new(db);

        if let Some(steps) = steps {
            info!("Rolling back {} applied migrations", steps);
        } else {
            info!("Rolling back all applied migrations");
        }

        let migrations = Self::get_applied_migrations(db).await?.into_iter().rev();
        if migrations.len() == 0 {
            info!("No applied migrations");
        }
        for Migration { migration, .. } in migrations {
            if let Some(steps) = steps.as_mut() {
                if steps == &0 {
                    break;
                }
                *steps -= 1;
            }
            info!("Rolling back migration '{}'", migration.name());
            migration.down(&manager).await?;
            info!("Migration '{}' has been rollbacked", migration.name());
            seaql_migrations::Entity::delete_many()
                .filter(seaql_migrations::Column::Version.eq(migration.name()))
                .exec(db)
                .await?;
        }

        Ok(())
    }

Implementors§