pub struct History { /* private fields */ }Expand description
A TOML-serializable record of all migrations that have been generated.
The history file lives at <migration_path>/history.toml and is the
source of truth for which migrations exist and what order they were
created in. Each entry is a HistoryEntry.
The file carries a version number. History::load and the FromStr
implementation reject files whose version does not match the current
format.
§Examples
use toasty_core::migration::{History, HistoryEntry};
let mut history = History::new();
assert_eq!(history.next_migration_number(), 0);
history.add_entry(HistoryEntry {
id: 100,
name: "0000_init.sql".to_string(),
snapshot_name: "0000_snapshot.toml".to_string(),
checksum: None,
});
assert_eq!(history.next_migration_number(), 1);
assert_eq!(history.entries().len(), 1);
// Round-trip through TOML serialization
let serialized = history.to_string();
let restored: History = serialized.parse().unwrap();
assert_eq!(restored.entries()[0].id, 100);Implementations§
Source§impl History
impl History
Sourcepub fn load_or_default(path: impl AsRef<Path>) -> Result<Self>
pub fn load_or_default(path: impl AsRef<Path>) -> Result<Self>
Loads the history file, or returns an empty one if it does not exist.
Sourcepub fn entries(&self) -> &[HistoryEntry]
pub fn entries(&self) -> &[HistoryEntry]
Returns the ordered list of entries in this history.
Entries appear in the order they were added. An empty slice means no migrations have been recorded yet.
§Examples
use toasty_core::migration::{History, HistoryEntry};
let mut history = History::new();
assert!(history.entries().is_empty());
history.add_entry(HistoryEntry {
id: 1,
name: "0001_init.sql".to_string(),
snapshot_name: "0001_snapshot.toml".to_string(),
checksum: None,
});
assert_eq!(history.entries().len(), 1);
assert_eq!(history.entries()[0].name, "0001_init.sql");Sourcepub fn next_migration_number(&self) -> u32
pub fn next_migration_number(&self) -> u32
Get the next migration number by parsing the last entry’s name.
Sourcepub fn add_entry(&mut self, entry: HistoryEntry)
pub fn add_entry(&mut self, entry: HistoryEntry)
Add an entry to the history.
Sourcepub fn remove_entry(&mut self, index: usize)
pub fn remove_entry(&mut self, index: usize)
Remove an entry from the history by index.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for History
impl<'de> Deserialize<'de> for History
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for History
impl RefUnwindSafe for History
impl Send for History
impl Sync for History
impl Unpin for History
impl UnsafeUnpin for History
impl UnwindSafe for History
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