pub struct HistoryFile { /* 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 HistoryFileMigration.
The file carries a version number. HistoryFile::load and the
FromStr implementation reject files whose version does not match the
current format.
§Examples
use toasty_cli::{HistoryFile, HistoryFileMigration};
let mut history = HistoryFile::new();
assert_eq!(history.next_migration_number(), 0);
history.add_migration(HistoryFileMigration {
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.migrations().len(), 1);
// Round-trip through TOML serialization
let serialized = history.to_string();
let restored: HistoryFile = serialized.parse().unwrap();
assert_eq!(restored.migrations()[0].id, 100);Implementations§
Source§impl HistoryFile
impl HistoryFile
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 migrations(&self) -> &[HistoryFileMigration]
pub fn migrations(&self) -> &[HistoryFileMigration]
Returns the ordered list of migrations in this history.
Migrations appear in the order they were added. An empty slice means no migrations have been recorded yet.
§Examples
use toasty_cli::{HistoryFile, HistoryFileMigration};
let mut history = HistoryFile::new();
assert!(history.migrations().is_empty());
history.add_migration(HistoryFileMigration {
id: 1,
name: "0001_init.sql".to_string(),
snapshot_name: "0001_snapshot.toml".to_string(),
checksum: None,
});
assert_eq!(history.migrations().len(), 1);
assert_eq!(history.migrations()[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 migration’s name
Sourcepub fn add_migration(&mut self, migration: HistoryFileMigration)
pub fn add_migration(&mut self, migration: HistoryFileMigration)
Add a migration to the history
Sourcepub fn remove_migration(&mut self, index: usize)
pub fn remove_migration(&mut self, index: usize)
Remove a migration from the history by index
Trait Implementations§
Source§impl Clone for HistoryFile
impl Clone for HistoryFile
Source§fn clone(&self) -> HistoryFile
fn clone(&self) -> HistoryFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more