Skip to main content

MigrationGraph

Struct MigrationGraph 

Source
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

Source

pub fn new() -> Self

Source

pub fn add(&mut self, migration: Migration) -> Result<(), GraphError>

Add a migration to the graph.

Source

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.

Source

pub fn heads(&self) -> Vec<&str>

Return IDs of all head migrations (those with no dependents).

Source

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.

Source

pub fn detect_conflict(&self) -> Result<(), GraphError>

Returns Err if there are multiple heads (conflict).

Source

pub fn validate_acyclic(&self) -> Result<(), GraphError>

Validate that the graph contains no cycles.

Source

pub fn topological_order(&self) -> Result<Vec<&str>, GraphError>

Produce a deterministic topological order of all migration IDs.

Source

pub fn create_merge_migration( &self, id: String, ) -> Result<Migration, GraphError>

Create an empty merge migration that depends on all current heads.

Source

pub fn get(&self, id: &str) -> Option<&Migration>

Source

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.

Trait Implementations§

Source§

impl Debug for MigrationGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MigrationGraph

Source§

fn default() -> MigrationGraph

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.