plan

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Save

func Save(p *Plan, dir string) (string, error)

Save writes the plan to a file in the given directory.

func Validate

func Validate(p *Plan, currentHash string) error

Validate checks that the plan's FromHash matches the current DB state hash.

Types

type ExecuteResult

type ExecuteResult struct {
	Completed int
	Total     int
	Error     error // nil if all steps succeeded
	FailStep  int   // which step failed (0 if none)
}

ExecuteResult holds the results of executing a plan.

func Execute

func Execute(ctx context.Context, conn *pgx.Conn, p *Plan) (*ExecuteResult, error)

Execute runs a plan step-by-step against the target database. Each step runs in its own transaction (if tx:true) or outside one (if tx:false). On failure, execution stops and the result indicates which step failed. Already-applied steps (from partial recovery) are skipped.

type Plan

type Plan struct {
	Name      string // filename without directory
	FromHash  string
	ToHash    string
	CreatedAt time.Time
	Steps     []*Step
}

Plan represents a migration plan file with per-step entries.

func FromDiffPlan

func FromDiffPlan(dp *diff.Plan) *Plan

FromDiffPlan converts a diff.Plan into a plan.Plan.

func Load

func Load(path string) (*Plan, error)

Load parses a plan file and returns the Plan.

func (*Plan) HasDestructive

func (p *Plan) HasDestructive() bool

HasDestructive checks if any step SQL contains destructive operations.

type Step

type Step struct {
	Index       int
	Type        string // e.g. "create_table", "add_column"
	Description string
	Tx          bool // whether to run in a transaction
	SQL         string
}

Step represents a single migration step within a plan.

Jump to

Keyboard shortcuts

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