pub struct MigrationState { /* private fields */ }Expand description
Tracks which migrations have been applied.
This struct provides an in-memory representation of the migration state. In a real application, you would load this from the database using the SQL constants provided in this module.
§Example
use oxide_sql_core::migrations::MigrationState;
let mut state = MigrationState::new();
// Check if a migration is applied
assert!(!state.is_applied("0001_initial"));
// Mark a migration as applied
state.mark_applied("0001_initial");
assert!(state.is_applied("0001_initial"));
// Mark a migration as unapplied (rolled back)
state.mark_unapplied("0001_initial");
assert!(!state.is_applied("0001_initial"));Implementations§
Source§impl MigrationState
impl MigrationState
Sourcepub fn from_applied(applied: impl IntoIterator<Item = String>) -> Self
pub fn from_applied(applied: impl IntoIterator<Item = String>) -> Self
Creates a migration state from a list of applied migration IDs.
This is useful for loading state from the database.
Sourcepub fn is_applied(&self, id: &str) -> bool
pub fn is_applied(&self, id: &str) -> bool
Checks if a migration has been applied.
Sourcepub fn mark_applied(&mut self, id: impl Into<String>)
pub fn mark_applied(&mut self, id: impl Into<String>)
Marks a migration as applied.
Sourcepub fn mark_unapplied(&mut self, id: &str)
pub fn mark_unapplied(&mut self, id: &str)
Marks a migration as unapplied (rolled back).
Sourcepub fn applied_migrations(&self) -> impl Iterator<Item = &str>
pub fn applied_migrations(&self) -> impl Iterator<Item = &str>
Returns an iterator over all applied migration IDs.
Sourcepub fn applied_count(&self) -> usize
pub fn applied_count(&self) -> usize
Returns the number of applied migrations.
Sourcepub const fn create_table_sql() -> &'static str
pub const fn create_table_sql() -> &'static str
Returns the SQL to create the migrations tracking table.
Sourcepub const fn insert_sql() -> &'static str
pub const fn insert_sql() -> &'static str
Returns the SQL to insert a migration record.
Sourcepub const fn delete_sql() -> &'static str
pub const fn delete_sql() -> &'static str
Returns the SQL to delete a migration record.
Trait Implementations§
Source§impl Clone for MigrationState
impl Clone for MigrationState
Source§fn clone(&self) -> MigrationState
fn clone(&self) -> MigrationState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MigrationState
impl Debug for MigrationState
Source§impl Default for MigrationState
impl Default for MigrationState
Source§fn default() -> MigrationState
fn default() -> MigrationState
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for MigrationState
impl RefUnwindSafe for MigrationState
impl Send for MigrationState
impl Sync for MigrationState
impl Unpin for MigrationState
impl UnwindSafe for MigrationState
Blanket Implementations§
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
Mutably borrows from an owned value. Read more