pub struct MigrationGraph { /* private fields */ }Expand description
Directed acyclic graph of migrations. Edges: dependency → dependent (A → B means B depends on A).
Implementations§
Source§impl MigrationGraph
impl MigrationGraph
pub fn new() -> Self
Sourcepub fn add(&mut self, migration: Migration) -> Result<(), GraphError>
pub fn add(&mut self, migration: Migration) -> Result<(), GraphError>
Add a migration to the graph.
Sourcepub fn validate_id(id: &str) -> Result<(), GraphError>
pub fn validate_id(id: &str) -> Result<(), GraphError>
Validate that an id is safe as a filename and unambiguous. Only lowercase letters, digits, and underscores are allowed. Called by Migrator before writing any new migration file.
Sourcepub fn next_number(&self) -> u32
pub fn next_number(&self) -> u32
Return the next sequential number (1-based) for a new migration. Parses the leading digits of each migration id (e.g. “0003_add_users” → 3). Returns 1 if the graph is empty.
Sourcepub fn detect_conflict(&self) -> Result<(), GraphError>
pub fn detect_conflict(&self) -> Result<(), GraphError>
Returns Err if there are multiple heads (conflict).
Sourcepub fn validate_acyclic(&self) -> Result<(), GraphError>
pub fn validate_acyclic(&self) -> Result<(), GraphError>
Validate that the graph contains no cycles.
Sourcepub fn topological_order(&self) -> Result<Vec<&str>, GraphError>
pub fn topological_order(&self) -> Result<Vec<&str>, GraphError>
Produce a deterministic topological order of all migration IDs.
Sourcepub fn create_merge_migration(
&self,
id: String,
) -> Result<Migration, GraphError>
pub fn create_merge_migration( &self, id: String, ) -> Result<Migration, GraphError>
Create an empty merge migration that depends on all current heads.
pub fn get(&self, id: &str) -> Option<&Migration>
Sourcepub fn resolve_id(&self, input: &str) -> Result<String, GraphError>
pub fn resolve_id(&self, input: &str) -> Result<String, GraphError>
Resolves an exact migration id or an unambiguous prefix in graph order.
Exact ids take precedence over prefixes. Ambiguous prefixes return all matching ids in deterministic topological order.