Skip to main content

migration

Attribute Macro migration 

Source
#[migration]
Expand description

Attribute macro for registering an escape-hatch SQL migration function.

The annotated async function is kept as-is and a MigrationRegistration is submitted to the inventory collector so modo_db::sync_and_migrate runs it in version order.

§Required arguments

  • version = <u64> — monotonically increasing migration version number.
  • description = "<text>" — human-readable description shown in logs.

§Optional argument

  • group = "<name>" — assigns the migration to a named group (default: "default"). Migrations in a group run only when modo_db::sync_and_migrate_group is called with the matching group name.

§Function signature

The annotated function must be async and accept a single &C parameter where C: ConnectionTrait. Return type must be Result<(), DbErr>.

§Example

#[modo_db::migration(version = 1, description = "seed default roles")]
async fn seed_roles(db: &impl modo_db::sea_orm::ConnectionTrait)
    -> Result<(), modo_db::sea_orm::DbErr>
{
    // run raw SQL or SeaORM operations
    Ok(())
}