migration

package
v0.1.0-preview.1.rc Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyUpToDate = errors.New("already up to date")

Known errors which we can ignore

Functions

func CloneNode

func CloneNode(n *yaml.Node) *yaml.Node

CloneNode deep-copies a *yaml.Node, preserving comments and anchors

func EnsureKeyWithComment

func EnsureKeyWithComment(root *yaml.Node, path []string, comment string)

EnsureKeyWithComment adds “# comment\nkey:” (with an empty sequence value) if key missing

func MigrateNode

func MigrateNode(
	user *yaml.Node,
	from, to string,
	chain []MigrationStep,
) (*yaml.Node, error)

MigrateNode runs all MigrationStep from 'from' to 'to' on the provided user YAML AST, returning the migrated AST

func MigrateYaml

func MigrateYaml(logger iface.Logger, path string, latestVersion string, migrationChain []MigrationStep) error

Run all migrations after current version upto latestVersion according to migrationChain

func ResolveNode

func ResolveNode(root *yaml.Node, path []string) *yaml.Node

ResolveNode walks the YAML AST following path segments and returns the node or nil

Types

type Always

type Always struct{}

Available conditions

func (Always) ShouldApply

func (Always) ShouldApply(_, _ *yaml.Node) bool

Always applies unconditionally

type IfUnchanged

type IfUnchanged struct{}

func (IfUnchanged) ShouldApply

func (IfUnchanged) ShouldApply(userNode, oldNode *yaml.Node) bool

IfUnchanged applies only if userNode equals oldNode

type MigrationStep

type MigrationStep struct {
	From    string
	To      string
	Apply   func(user, oldDef, newDef *yaml.Node) (*yaml.Node, error)
	OldYAML []byte
	NewYAML []byte
}

MigrationStep represents one version-to-version migration

type PatchCondition

type PatchCondition interface {
	// ShouldApply returns true if the userNode should be patched based on oldNode
	ShouldApply(userNode, oldNode *yaml.Node) bool
}

PatchCondition defines a node-level condition

type PatchEngine

type PatchEngine struct {
	Old   *yaml.Node
	New   *yaml.Node
	User  *yaml.Node
	Rules []PatchRule
}

PatchEngine applies a set of PatchRule against a user YAML AST preserving order, comments, and anchors

func (*PatchEngine) Apply

func (e *PatchEngine) Apply() error

Apply walks each rule, and when Condition is met, either removes the node or replaces it with a (transformed) copy

type PatchRule

type PatchRule struct {
	// Path: sequence of map keys or sequence indices (as strings)
	Path []string
	// Condition: returns true if the patch should apply
	Condition PatchCondition
	// Transform: optional node-level transformation on the new node
	Transform func(newNode *yaml.Node) *yaml.Node
	// Remove: if true, delete the node instead of patching
	Remove bool
}

PatchRule defines a YAML node patch rule

type VersionComparator

type VersionComparator func(string, string) bool

VersionGreaterThan uses semantic dot-separated compare for strings

Jump to

Keyboard shortcuts

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