Expand description
§version-migrate
A library for explicit, type-safe schema versioning and migration.
§Example
ⓘ
use version_migrate::{Versioned, MigratesTo, IntoDomain, Migrator};
use serde::{Serialize, Deserialize};
// Version 1.0.0
#[derive(Serialize, Deserialize, Versioned)]
#[versioned(version = "1.0.0")]
struct TaskV1_0_0 {
id: String,
title: String,
}
// Version 1.1.0
#[derive(Serialize, Deserialize, Versioned)]
#[versioned(version = "1.1.0")]
struct TaskV1_1_0 {
id: String,
title: String,
description: Option<String>,
}
// Domain model
struct TaskEntity {
id: String,
title: String,
description: Option<String>,
}
impl MigratesTo<TaskV1_1_0> for TaskV1_0_0 {
fn migrate(self) -> TaskV1_1_0 {
TaskV1_1_0 {
id: self.id,
title: self.title,
description: None,
}
}
}
impl IntoDomain<TaskEntity> for TaskV1_1_0 {
fn into_domain(self) -> TaskEntity {
TaskEntity {
id: self.id,
title: self.title,
description: self.description,
}
}
}Re-exports§
pub use errors::MigrationError;
Modules§
- errors
- Error types for migration operations.
Structs§
- Migration
Path - A complete migration path from versioned DTOs to a domain model.
- Migrator
- The migration manager that orchestrates all migrations.
- Versioned
Wrapper - A wrapper for serialized data that includes explicit version information.
Traits§
- Async
Into Domain - Async version of
IntoDomainfor domain conversions requiring I/O operations. - Async
Migrates To - Async version of
MigratesTofor migrations requiring I/O operations. - Into
Domain - Converts a versioned DTO into the application’s domain model.
- Migrates
To - Defines explicit migration logic from one version to another.
- Versioned
- A trait for versioned data schemas.
Attribute Macros§
Derive Macros§
- Versioned
- Derives the
Versionedtrait for a struct.