plan

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directive

type Directive struct {
	Type    DirectiveType `json:"type"`    // DirectiveTypeWait, etc.
	Message string        `json:"message"` // Auto-generated descriptive message
}

Directive represents a special directive for execution (wait, assert, etc.)

type DirectiveType

type DirectiveType string

DirectiveType represents the different types of directives

const (
	DirectiveTypeWait DirectiveType = "wait"
)

func (DirectiveType) String

func (dt DirectiveType) String() string

String returns the string representation of DirectiveType

type ExecutionGroup

type ExecutionGroup struct {
	Steps []Step `json:"steps"`
}

ExecutionGroup represents a group of steps that should be executed together

type Plan

type Plan struct {
	// Version information
	Version         string `json:"version"`
	PgschemaVersion string `json:"pgschema_version"`

	// When the plan was created
	CreatedAt time.Time `json:"created_at"`

	// Source database fingerprint when plan was created
	SourceFingerprint *fingerprint.SchemaFingerprint `json:"source_fingerprint,omitempty"`

	// Groups is the ordered list of execution groups
	Groups []ExecutionGroup `json:"groups"`

	// SourceDiffs stores original diff information for summary calculation
	// This field is only serialized in debug mode
	SourceDiffs []diff.Diff `json:"source_diffs,omitempty"`
}

Plan represents the migration plan between two DDL states

func FromJSON

func FromJSON(jsonData []byte) (*Plan, error)

FromJSON creates a Plan from JSON data

func NewPlan

func NewPlan(diffs []diff.Diff) *Plan

NewPlan creates a new plan from a list of diffs with online operations enabled

func NewPlanWithFingerprint

func NewPlanWithFingerprint(diffs []diff.Diff, sourceFingerprint *fingerprint.SchemaFingerprint) *Plan

NewPlanWithFingerprint creates a new plan from diffs and includes source fingerprint

func (*Plan) HasAnyChanges

func (p *Plan) HasAnyChanges() bool

HasAnyChanges checks if the plan contains any changes by examining the groups

func (*Plan) HumanColored

func (p *Plan) HumanColored(enableColor bool) string

HumanColored returns a human-readable summary of the plan with color support

func (*Plan) ToJSON

func (p *Plan) ToJSON() (string, error)

ToJSON returns the plan as structured JSON with only changed statements

func (*Plan) ToJSONWithDebug

func (p *Plan) ToJSONWithDebug(includeSource bool) (string, error)

ToJSONWithDebug returns the plan as structured JSON with optional source field inclusion

func (*Plan) ToSQL

func (p *Plan) ToSQL(format SQLFormat) string

ToSQL returns the SQL statements with formatting based on the specified format

type PlanSummary

type PlanSummary struct {
	Total   int                    `json:"total"`
	Add     int                    `json:"add"`
	Change  int                    `json:"change"`
	Destroy int                    `json:"destroy"`
	ByType  map[string]TypeSummary `json:"by_type"`
}

PlanSummary provides counts of changes by type

type RewriteStep

type RewriteStep struct {
	SQL                 string     `json:"sql,omitempty"`
	CanRunInTransaction bool       `json:"can_run_in_transaction"`
	Directive           *Directive `json:"directive,omitempty"`
}

RewriteStep represents a single step in a rewrite operation

type SQLFormat

type SQLFormat string

SQLFormat represents the different output formats for SQL generation

const (
	// SQLFormatRaw outputs just the raw SQL statements without additional formatting
	SQLFormatRaw SQLFormat = "raw"
	// Human-readable format with comments
	SQLFormatHuman SQLFormat = "human"
)

type Step

type Step struct {
	SQL       string     `json:"sql"`
	Directive *Directive `json:"directive,omitempty"`
	// Metadata for summary generation
	Type      string `json:"type,omitempty"`      // e.g., "table", "index"
	Operation string `json:"operation,omitempty"` // e.g., "create", "alter", "drop"
	Path      string `json:"path,omitempty"`      // e.g., "public.users"
}

Step represents a single execution step with SQL and optional directive

type Type

type Type string

Type represents the database object types in dependency order

const (
	TypeSchema                  Type = "schemas"
	TypeType                    Type = "types"
	TypeFunction                Type = "functions"
	TypeProcedure               Type = "procedures"
	TypeSequence                Type = "sequences"
	TypeTable                   Type = "tables"
	TypeView                    Type = "views"
	TypeMaterializedView        Type = "materialized views"
	TypeIndex                   Type = "indexes"
	TypeTrigger                 Type = "triggers"
	TypePolicy                  Type = "policies"
	TypeColumn                  Type = "columns"
	TypeRLS                     Type = "rls"
	TypeDefaultPrivilege        Type = "default privileges"
	TypePrivilege               Type = "privileges"
	TypeColumnPrivilege         Type = "column privileges"
	TypeRevokedDefaultPrivilege Type = "revoked default privileges"
)

type TypeSummary

type TypeSummary struct {
	Add     int `json:"add"`
	Change  int `json:"change"`
	Destroy int `json:"destroy"`
}

TypeSummary provides counts for a specific object type

Jump to

Keyboard shortcuts

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