Table of Contents

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

componentTypeName string

The fully-qualified name of the component type.

currentVersion int

The 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

string

CurrentVersion

Gets the current version of the component.

public int CurrentVersion { get; }

Property Value

int

EdgeCount

Gets the total number of migration edges in the graph.

public int EdgeCount { get; }

Property Value

int

SourceVersions

Gets all source versions that have migrations defined.

public IEnumerable<int> SourceVersions { get; }

Property Value

IEnumerable<int>

Methods

AddEdge(int, int)

Adds a migration edge from one version to another.

public void AddEdge(int fromVersion, int toVersion)

Parameters

fromVersion int

The source version.

toVersion int

The target version (typically fromVersion + 1).

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

fromVersion int

The source version.

toVersion int

The target version.

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

true if a cycle is detected; false otherwise.

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

fromVersion int

The source version.

toVersion int

The target version.

Returns

bool

true if a complete migration chain exists; false otherwise.

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

newVersion int

The 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.