#[migration]Expand description
Attribute macro that wraps a migration function into a MigrationStep.
The function must take a single argument (the old version’s data) and return
the new version’s data. Both types must implement Serialize and DeserializeOwned.
§Attributes
from = N— Required. Source schema version.to = M— Required. Target schema version.
§Generated Code
Creates a struct {FnName}Migration that implements MigrationStep.
The struct handles deserialization of the old format, calls your function,
and serializes the result.
Also generates a register_{fn_name} function that returns a boxed
MigrationStep for convenient registration.
§Example
ⓘ
use crdt_migrate_macros::migration;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct SensorV1 { temperature: f32 }
#[derive(Serialize, Deserialize)]
struct SensorV2 { temperature: f32, humidity: Option<f32> }
#[migration(from = 1, to = 2)]
fn add_humidity(old: SensorV1) -> SensorV2 {
SensorV2 {
temperature: old.temperature,
humidity: None,
}
}
// Generates: AddHumidityMigration struct + impl MigrationStep
// Generates: fn register_add_humidity() -> Box<dyn MigrationStep>