diff

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FunctionReferencesRelation added in v1.13.0

func FunctionReferencesRelation(fn *ir.Function, relations map[string]struct{}) bool

FunctionReferencesRelation reports whether a function's signature or body references a relation in the lookup (see RelationLookup). This is the same check the diff uses to order functions after the tables they query (#530).

func FunctionSignatureReferencesRelation added in v1.13.0

func FunctionSignatureReferencesRelation(fn *ir.Function, relations map[string]struct{}) bool

FunctionSignatureReferencesRelation reports whether a function's return type or parameter types name a relation in the lookup (see RelationLookup). Such a function must be created after that relation exists.

func GenerateDumpHeader

func GenerateDumpHeader(schemaIR *ir.IR) string

GenerateDumpHeader generates the header for database dumps with metadata

func RelationLookup added in v1.13.0

func RelationLookup(tables []*ir.Table, views []*ir.View) map[string]struct{}

RelationLookup builds a case-insensitive lookup of table and view names, keyed both unqualified and schema-qualified, for use with FunctionSignatureReferencesRelation.

Types

type ColumnDiff

type ColumnDiff struct {
	Old *ir.Column
	New *ir.Column
}

ColumnDiff represents changes to a column

func (*ColumnDiff) GetObjectName

func (d *ColumnDiff) GetObjectName() string

type ConstraintDiff

type ConstraintDiff struct {
	Old *ir.Constraint
	New *ir.Constraint
}

ConstraintDiff represents changes to a constraint

func (*ConstraintDiff) GetObjectName

func (d *ConstraintDiff) GetObjectName() string

type Diff

type Diff struct {
	Statements []SQLStatement `json:"statements"`
	Type       DiffType       `json:"type"`
	Operation  DiffOperation  `json:"operation"` // create, alter, drop, replace
	Path       string         `json:"path"`
	Source     DiffSource     `json:"-"` // interface; not JSON-serializable (see #305)
}

Diff represents one or more related SQL statements with their source change

func GenerateDump added in v1.13.2

func GenerateDump(schema *ir.IR, targetSchema string, qualifySchema bool) ([]Diff, error)

GenerateDump creates an empty-to-target export while preserving partitioned index identities. Migrations use the same schedule for complete new hierarchies.

func GenerateMigration

func GenerateMigration(oldIR, newIR *ir.IR, targetSchema string) []Diff

GenerateMigration compares two IR schemas and returns the SQL differences GenerateMigration generates the migration diff using standard "smart qualification" (the target-schema prefix is omitted on entity names).

func GenerateMigrationForTarget added in v1.13.1

func GenerateMigrationForTarget(oldIR, newIR *ir.IR, targetSchema string, targetMajorVersion int) []Diff

GenerateMigrationForTarget is GenerateMigration for a target database whose PostgreSQL major version is known (0 if unknown, treated as a current server). The version gates DDL that only newer servers accept, such as ALTER COLUMN ... SET EXPRESSION AS (PostgreSQL 17+); older targets get a version-portable equivalent instead (issue #591).

func GenerateMigrationWithOptions added in v1.12.0

func GenerateMigrationWithOptions(oldIR, newIR *ir.IR, targetSchema string, qualifySchema bool) []Diff

GenerateMigrationWithOptions is like GenerateMigration, but when qualifySchema is true the empty-to-target create DDL used by `dump --qualify-schema` forces schema qualification for structural object identifiers where the IR carries schema identity (table/view/index/sequence/type/function/procedure/policy names and ON/REFERENCES/OWNED BY/COMMENT targets). This option is intended for dump's empty-to-target CREATE/ADD output; other diff paths are not part of the contract and may still use standard smart qualification. Same-schema type references stay bare because the IR stores them without schema identity (#493). Default behavior (false) is unchanged for plan/apply.

type DiffOperation

type DiffOperation int

DiffOperation represents the operation being performed

const (
	DiffOperationCreate DiffOperation = iota
	DiffOperationAlter
	DiffOperationDrop
	// DiffOperationRecreate indicates a DROP that is part of a DROP+CREATE cycle
	// for dependency handling. The object will be recreated, so this should be
	// counted as a modification in summaries, not a destruction.
	DiffOperationRecreate
	// DiffOperationAttach indicates an explicit partition index attachment.
	DiffOperationAttach
)

func (DiffOperation) MarshalJSON

func (d DiffOperation) MarshalJSON() ([]byte, error)

MarshalJSON marshals DiffOperation to JSON as a string

func (DiffOperation) String

func (d DiffOperation) String() string

String returns the string representation of DiffOperation

func (*DiffOperation) UnmarshalJSON

func (d *DiffOperation) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals DiffOperation from JSON string

type DiffSource

type DiffSource interface {
	GetObjectName() string // Returns the object name (preserves names with dots like "public.idx_users")
}

DiffSource represents all possible source types for a diff

type DiffType

type DiffType int

DiffType represents the type of database object being changed

const (
	DiffTypeTable DiffType = iota
	DiffTypeTableColumn
	DiffTypeTableIndex
	DiffTypeTableTrigger
	DiffTypeTablePolicy
	DiffTypeTableRLS
	DiffTypeTableConstraint
	DiffTypeTableComment
	DiffTypeTableColumnComment
	DiffTypeTableIndexComment
	DiffTypeTablePersistence
	DiffTypeView
	DiffTypeViewTrigger
	DiffTypeViewComment
	DiffTypeMaterializedView
	DiffTypeMaterializedViewComment
	DiffTypeMaterializedViewIndex
	DiffTypeMaterializedViewIndexComment
	DiffTypeFunction
	DiffTypeProcedure
	DiffTypeAggregate
	DiffTypeSequence
	DiffTypeType
	DiffTypeDomain
	DiffTypeComment
	DiffTypeDefaultPrivilege
	DiffTypePrivilege
	DiffTypeRevokedDefaultPrivilege
	DiffTypeColumnPrivilege
)

func (DiffType) MarshalJSON

func (d DiffType) MarshalJSON() ([]byte, error)

MarshalJSON marshals DiffType to JSON as a string

func (DiffType) String

func (d DiffType) String() string

String returns the string representation of DiffType

func (*DiffType) UnmarshalJSON

func (d *DiffType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals DiffType from JSON string

type IndexDiff

type IndexDiff struct {
	Old *ir.Index
	New *ir.Index
}

IndexDiff represents changes to an index

func (*IndexDiff) GetObjectName

func (d *IndexDiff) GetObjectName() string

type SQLStatement

type SQLStatement struct {
	SQL                 string `json:"sql,omitempty"`
	CanRunInTransaction bool   `json:"can_run_in_transaction"`
	// RequiresCommitAfter forces a transaction boundary right after this
	// statement: later statements must not share its transaction. Used for
	// ALTER TYPE ... ADD VALUE, whose new label is unusable until committed
	// (SQLSTATE 55P04, issue #600).
	RequiresCommitAfter bool `json:"-"`
}

SQLStatement represents a single SQL statement with its transaction capability

Jump to

Keyboard shortcuts

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