migrator

Macro migrator 

Source
macro_rules! migrator {
    ($entity:expr => [$first:ty, $($rest:ty),+ $(,)?]) => { ... };
    ($entity:expr => [$first:ty, $($rest:ty),+ $(,)?], version_key = $version_key:expr, data_key = $data_key:expr) => { ... };
    ($($entity:expr => [$first:ty, $($rest:ty),+ $(,)?]),+ $(,)?) => { ... };
}
Expand description

Creates a fully initialized Migrator with registered migration paths.

This macro creates a Migrator instance and registers one or more migration paths, returning a ready-to-use migrator. This is the recommended way to create a migrator as it’s more concise than manually calling Migrator::new() and register() for each path.

§Syntax

Single path:

migrator!("entity" => [V1, V2, V3])

Multiple paths:

migrator!(
    "task" => [TaskV1, TaskV2, TaskV3],
    "user" => [UserV1, UserV2]
)

With custom keys:

migrator!(
    "task" => [TaskV1, TaskV2], version_key = "v", data_key = "d"
)

§Examples

use version_migrate::migrator;

// Single entity migration
let migrator = migrator!("task" => [TaskV1, TaskV2, TaskV3]).unwrap();

// Multiple entities
let migrator = migrator!(
    "task" => [TaskV1, TaskV2],
    "user" => [UserV1, UserV2]
).unwrap();

// Now ready to use
let domain: TaskEntity = migrator.load("task", json_str)?;

§Returns

Returns Result<Migrator, MigrationError>. The migrator is ready to use if Ok.