graph

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

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 (g *Graph) AdjacencyMap() (map[int64]map[int64]graphlib.Edge[int64], error)

func (*Graph) Draw

func (g *Graph) Draw(w io.Writer) error

func (*Graph) GetDefinition

func (g *Graph) GetDefinition(timestamp int64) (types.Definition, error)

func (*Graph) Leaves

func (g *Graph) Leaves() ([]int64, error)

func (*Graph) Order

func (g *Graph) Order() (int, error)

func (*Graph) TopologicalSort

func (g *Graph) TopologicalSort() ([]int64, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址