mongodb_migrator/migration.rs
1//! In order to treat the entity as migrationable it should implement [`Migration`] trait
2use anyhow::Result;
3use async_trait::async_trait;
4
5use crate::migrator::Env;
6
7#[async_trait]
8pub trait Migration: Sync + Send {
9 /// Runs a migration.
10 async fn up(&self, env: Env) -> Result<()>;
11
12 /// Rollbacks a migration.
13 /// Since not every migration could be rollbacked
14 /// and it often happens there is a blank implementation
15 async fn down(&self, _env: Env) -> Result<()> {
16 Ok(())
17 }
18
19 /// A status about a migration will be stored in a db collection with the following document id
20 /// We can pass an id manually otherwise it will be based on the type name so that uniqueness per project
21 /// is guaranteed out of the box
22 fn get_id(&self) -> &str {
23 std::any::type_name::<Self>()
24 }
25}