migrate_path

Macro migrate_path 

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

Creates a migration path with simplified syntax.

This macro provides a concise way to define migration paths between versioned types. Use this when you need just the path without creating a Migrator instance.

§Syntax

Basic usage:

migrate_path!("entity", [V1, V2, V3])

With custom version/data keys:

migrate_path!("entity", [V1, V2, V3], version_key = "v", data_key = "d")

§Arguments

  • entity - The entity name as a string literal (e.g., "user", "task")
  • versions - A list of version types in migration order (e.g., [V1, V2, V3])
  • version_key - (Optional) Custom key for the version field (default: "version")
  • data_key - (Optional) Custom key for the data field (default: "data")

§Examples

use version_migrate::{migrate_path, Migrator};

// Simple two-step migration
let path = migrate_path!("task", [TaskV1, TaskV2]);

// Multi-step migration
let path = migrate_path!("task", [TaskV1, TaskV2, TaskV3]);

// Many versions (arbitrary length supported)
let path = migrate_path!("task", [TaskV1, TaskV2, TaskV3, TaskV4, TaskV5, TaskV6]);

// With custom keys
let path = migrate_path!("task", [TaskV1, TaskV2], version_key = "v", data_key = "d");

// Register with migrator
let mut migrator = Migrator::new();
migrator.register(path).unwrap();

§Generated Code

The macro expands to the equivalent builder pattern:

// migrate_path!("entity", [V1, V2])
// expands to:
Migrator::define("entity")
    .from::<V1>()
    .into::<V2>()