mig

package
v0.0.0-...-feac9d9 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

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
}

Graph represents a set of unit files with dependencies that form a Direct Acyclic Graph.

func NewGraph

func NewGraph() *Graph

NewGraph creates a graph that only contains the "nothing" unit which is used to bootstrap units without dependencies.

This is necessary because the graph has no concept of a node without dependency. This makes determining executable nodes much easier (search for nodes with executed dependencies instead of the former *and* searching for nodes without dependencies)

func (*Graph) CanExecuteNode

func (g *Graph) CanExecuteNode(name string) bool

CanExecuteNode returns true if the specified node is executeable, if the key is not present or the node cannot be executed, it return false

func (*Graph) GetAllRunnableNodes

func (g *Graph) GetAllRunnableNodes() []string

GetAllRunnableNodes returns a list of all nodes that can be executed on the current graph or an empty slice.

func (*Graph) GetTargetSubgraph

func (g *Graph) GetTargetSubgraph(targetName string) (*Graph, error)

GetTargetSubgraph will take a target and create a graph that only contains nodes that are direct or indirect dependencies of that target. If a unit is not reachable from the current target, it will not be included in the subgraph.

func (*Graph) GetUnit

func (g *Graph) GetUnit(name string) (Unit, error)

GetUnit returns the specified Unit as a struct

func (*Graph) IsStuck

func (g *Graph) IsStuck() bool

IsStuck determines if the graph can continue to execute nodes. To check this, IsStick counts how many unexecuted nodes are on the graph and then checks if any nodes can be executed. If there are unexecuted nodes but we cannot execute any nodes, then we are stuck. To ensure this check does not trigger, you should select a target and use GetTargetSubgraph to obtain a graph only containing the target's dependencies, direct or indirect.

func (*Graph) Load

func (g *Graph) Load(basepath string) error

Load will use go.rice to load an embedded resources (or from LocalFS if not found) into the graph

func (*Graph) MarkNodesRun

func (g *Graph) MarkNodesRun(names ...string) error

MarkNodesRun will mark a node as executed on the graph, allowing the graph to proceed the execution.

func (*Graph) RemainingSize

func (g *Graph) RemainingSize() int

RemainingSize indicates how many nodes need to be executed still

func (*Graph) Size

func (g *Graph) Size() int

Size returns the total number of nodes on the graph

func (*Graph) ValidateNodes

func (g *Graph) ValidateNodes() error

ValidateNodes will check that the graph is properly formed but will not check for cycles.

A properly formed graph contains nodes where their key in the internal map and their name match, that nodes always have a dependency if they have not been executed and that the dependencies of all nodes exist.

If this function returns no error then it is guaranteed that the graph is directed and may be acyclic.

type PostgresDialect

type PostgresDialect struct {
	// contains filtered or unexported fields
}

PostgresDialect implements a Postgres compatible interface to perform database migration using the mig toolkit

func OpenFromPGConn

func OpenFromPGConn(db *sql.DB) *PostgresDialect

OpenFromPGConn accepts a opened database connections and wraps it into the PostgresDialect

func (*PostgresDialect) CheckAndLoadTables

func (d *PostgresDialect) CheckAndLoadTables() error

CheckAndLoadTables will determine if the database is reachable and create the migration table

func (*PostgresDialect) GetExecutedUnits

func (d *PostgresDialect) GetExecutedUnits() ([]string, error)

GetExecutedUnits returns a list of executed units present in the migration table

func (*PostgresDialect) MarkExecuted

func (d *PostgresDialect) MarkExecuted(unit Unit) error

MarkExecuted will put a unit into the migration table unless it's marked as "always_exec: true" or a target unit

type SQLSection

type SQLSection struct {
	// Postgres contains the PG/SQL string to be executed for the unit
	Postgres string `yaml:"postgres"`
}

SQLSection defines the SQLQueries for various dialects. At the moment only postgres is implemented since a graph-based migration requires a DDL-level transaction to be safe

type Unit

type Unit struct {
	Name        string     `yaml:"-"`
	Description string     `yaml:"description"`
	DependsOn   []string   `yaml:"depends_on"`
	AlwaysExec  bool       `yaml:"always_exec"`
	Type        UnitType   `yaml:"type"`
	SQL         SQLSection `yaml:"sql"`
	// contains filtered or unexported fields
}

Unit contains the definition of a migration unit that is represented by a node in a DAG

func (Unit) DependsOnWithoutNothing

func (u Unit) DependsOnWithoutNothing() []string

DependsOnWithoutNothing returns the list of dependencies that are not "nothing" Normally a unit should not depend on the "nothing" unit if it has other dependencies.

type UnitType

type UnitType string

UnitType defines how a unit is treated on the graph

const (
	// UnitTypeMigration defines a migration unit which executed SQLCode
	UnitTypeMigration UnitType = "migration"
	// UnitTypeVirtualTarget defines a target unit which groups various units together without executing code
	UnitTypeVirtualTarget = "target"
)

Jump to

Keyboard shortcuts

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