ormada_data_migration

Attribute Macro ormada_data_migration 

Source
#[ormada_data_migration]
Expand description

Attribute macro for data migrations

Marks an async function as a data migration that runs after schema changes. The function receives a database connection and uses the standard Ormada ORM API.

§Usage

use ormada::migration::prelude::*;
use crate::models::Author;

#[ormada_data_migration(migration = "003", after = "002")]
async fn populate_emails(db: &DatabaseConnection) -> Result<(), OrmadaError> {
    // Use the same Ormada ORM API as your application code!
    Author::objects(db)
        .filter(Author::Email.is_null())
        .update_all(|author| {
            author.email = format!("{}@example.com", author.name.to_lowercase());
        })
        .await?;

    Ok(())
}

§Attributes

  • migration = "id" - (required) Migration identifier
  • after = "id" - Migration this depends on