pub struct SchemaEvolutionManager { /* private fields */ }Expand description
Thread-safe registry that applies versioned SchemaMigrations to an
ongoing stream without reconnecting.
§Concurrency
The migration map is protected by a parking_lot::RwLock. Version
counters use atomic operations so read-heavy workloads need no exclusive
locks.
Implementations§
Source§impl SchemaEvolutionManager
impl SchemaEvolutionManager
Sourcepub fn new(initial_version: u64) -> Arc<Self> ⓘ
pub fn new(initial_version: u64) -> Arc<Self> ⓘ
Create a new manager starting at initial_version.
Returns an Arc-wrapped instance so it can be shared across tasks.
Sourcepub fn register_migration(&self, migration: SchemaMigration) -> bool
pub fn register_migration(&self, migration: SchemaMigration) -> bool
Register a migration.
Returns false if a migration for migration.from_version is already
registered (duplicate registration is silently rejected).
Sourcepub fn migration_path(
&self,
from_version: u64,
to_version: u64,
) -> Option<Vec<SchemaMigration>>
pub fn migration_path( &self, from_version: u64, to_version: u64, ) -> Option<Vec<SchemaMigration>>
Compute the ordered sequence of migrations needed to go from
from_version to to_version.
Only forward paths (strictly increasing version numbers) are
supported. Returns None when no complete path exists.
Sourcepub fn migrate_to(
&self,
target_version: u64,
) -> Result<Vec<SchemaMigration>, MigrationError>
pub fn migrate_to( &self, target_version: u64, ) -> Result<Vec<SchemaMigration>, MigrationError>
Apply all migrations necessary to reach target_version.
§Errors
MigrationError::AlreadyAtVersion— current version equals target.MigrationError::Downgrade— target is less than current version.MigrationError::NoPath— no registered path leads to target.
Sourcepub fn current_version(&self) -> u64
pub fn current_version(&self) -> u64
Return the current schema version.
Sourcepub fn applied_count(&self) -> u64
pub fn applied_count(&self) -> u64
Return the total number of migrations applied since creation.
Sourcepub fn can_migrate(&self, from_version: u64, to_version: u64) -> bool
pub fn can_migrate(&self, from_version: u64, to_version: u64) -> bool
Return true when a migration path from from_version to
to_version is available.
Sourcepub fn registered_versions(&self) -> Vec<u64>
pub fn registered_versions(&self) -> Vec<u64>
Return all registered from_version values, in ascending order.
Auto Trait Implementations§
impl !Freeze for SchemaEvolutionManager
impl !RefUnwindSafe for SchemaEvolutionManager
impl Send for SchemaEvolutionManager
impl Sync for SchemaEvolutionManager
impl Unpin for SchemaEvolutionManager
impl UnsafeUnpin for SchemaEvolutionManager
impl UnwindSafe for SchemaEvolutionManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more