Class MigrationGraph
- Namespace
- KeenEyes.Serialization
- Assembly
- KeenEyes.Core.dll
Represents a migration graph for a single component type.
public sealed class MigrationGraph
- Inheritance
-
MigrationGraph
- Inherited Members
Examples
var graph = new MigrationGraph("MyComponent");
graph.AddEdge(1, 2); // v1 → v2 migration exists
graph.AddEdge(2, 3); // v2 → v3 migration exists
// Check if we can migrate from v1 to v3
if (graph.HasPath(1, 3))
{
var chain = graph.GetMigrationChain(1, 3);
// chain = [(1, 2), (2, 3)]
}
Remarks
A migration graph models the available version transitions for a component. Each edge represents a migration from one version to another (e.g., v1 → v2).
The graph provides:
- Path validation with caching for efficient repeated lookups
- Topological chain resolution for multi-step migrations
- Cycle detection (though cycles are structurally impossible with version-incrementing migrations)
- Diagnostic visualization of available migration paths
Constructors
MigrationGraph(string, int)
Represents a migration graph for a single component type.
public MigrationGraph(string componentTypeName, int currentVersion = 1)
Parameters
componentTypeNamestringThe fully-qualified name of the component type.
currentVersionintThe current version of the component (default is 1).
Examples
var graph = new MigrationGraph("MyComponent");
graph.AddEdge(1, 2); // v1 → v2 migration exists
graph.AddEdge(2, 3); // v2 → v3 migration exists
// Check if we can migrate from v1 to v3
if (graph.HasPath(1, 3))
{
var chain = graph.GetMigrationChain(1, 3);
// chain = [(1, 2), (2, 3)]
}
Remarks
A migration graph models the available version transitions for a component. Each edge represents a migration from one version to another (e.g., v1 → v2).
The graph provides:
- Path validation with caching for efficient repeated lookups
- Topological chain resolution for multi-step migrations
- Cycle detection (though cycles are structurally impossible with version-incrementing migrations)
- Diagnostic visualization of available migration paths
Properties
ComponentTypeName
Gets the component type name this graph represents.
public string ComponentTypeName { get; }
Property Value
CurrentVersion
Gets the current version of the component.
public int CurrentVersion { get; }
Property Value
EdgeCount
Gets the total number of migration edges in the graph.
public int EdgeCount { get; }
Property Value
SourceVersions
Gets all source versions that have migrations defined.
public IEnumerable<int> SourceVersions { get; }
Property Value
Methods
AddEdge(int, int)
Adds a migration edge from one version to another.
public void AddEdge(int fromVersion, int toVersion)
Parameters
Exceptions
- ArgumentException
Thrown when fromVersion >= toVersion (migrations must go forward).
ClearCache()
Clears the path and chain caches.
public void ClearCache()
FindGaps()
Finds any gaps in the migration chain from version 1 to the current version.
public IReadOnlyList<int> FindGaps()
Returns
- IReadOnlyList<int>
A list of version numbers that are missing migrations (i.e., no edge from v to v+1).
GetMigrationChain(int, int)
Gets the migration chain required to migrate from one version to another.
public IReadOnlyList<MigrationStep> GetMigrationChain(int fromVersion, int toVersion)
Parameters
Returns
- IReadOnlyList<MigrationStep>
A list of migration steps representing the shortest path, or an empty list if no path exists.
Remarks
For standard version-incrementing migrations (v1→v2→v3), this returns the linear chain. Results are cached for performance.
HasCycle()
Checks if the graph contains any cycles.
public bool HasCycle()
Returns
- bool
trueif a cycle is detected;falseotherwise.
Remarks
With version-incrementing migrations (fromVersion < toVersion), cycles are structurally impossible. This method is provided for validation completeness.
HasPath(int, int)
Checks if a migration path exists from one version to another.
public bool HasPath(int fromVersion, int toVersion)
Parameters
Returns
- bool
trueif a complete migration chain exists;falseotherwise.
Remarks
Results are cached for performance. Use ClearCache() to invalidate.
SetCurrentVersion(int)
Sets the current version of the component.
public void SetCurrentVersion(int newVersion)
Parameters
newVersionintThe current version number.
ToDiagnosticString()
Generates a diagnostic string representation of the migration graph.
public string ToDiagnosticString()
Returns
- string
A multi-line string describing the graph structure.