Documentation
¶
Overview ¶
Package graph provides a directed acyclic graph (DAG) implementation for managing migration dependencies. It uses the dominikbraun/graph library to create and manipulate migration graphs, ensuring proper execution order and detecting cycles.
The graph representation allows for:
- Computing topological ordering of migrations
- Detecting circular dependencies
- Exporting migration graphs for visualization
- Efficient dependency resolution
Index ¶
- type Graph
- func (g *Graph) AddDefinition(def types.Definition) error
- func (g *Graph) AddDefinitions(defs ...types.Definition) error
- func (g *Graph) AdjacencyMap() (map[int64]map[int64]graphlib.Edge[int64], error)
- func (g *Graph) Draw(w io.Writer) error
- func (g *Graph) GetDefinition(timestamp int64) (types.Definition, error)
- func (g *Graph) Leaves() ([]int64, error)
- func (g *Graph) Order() (int, error)
- func (g *Graph) TopologicalSort() ([]int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
func New ¶
func New() *Graph
New creates a DAG (Directed Acyclic graph) to represent a migration. This makes it easy to compute execution order for migrations and also to export the graph as a digraph diagram.
You can visualize using an online tool like: https://dreampuf.github.io/GraphvizOnline
func (*Graph) AddDefinition ¶
func (g *Graph) AddDefinition(def types.Definition) error
func (*Graph) AddDefinitions ¶
func (g *Graph) AddDefinitions(defs ...types.Definition) error
func (*Graph) AdjacencyMap ¶
func (*Graph) GetDefinition ¶
func (g *Graph) GetDefinition(timestamp int64) (types.Definition, error)
func (*Graph) TopologicalSort ¶
TopologicalSort returns a valid topological ordering of all the vertices in the graph. It uses StableTopologicalSort from the graph library to ensure that elements with valid topological ordering are consistently returned in order of their timestamps (i < j), making the results deterministic and predictable.