diff

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: 6 Imported by: 0

Documentation

Index

Constants

View Source
const IndexBTree = schema.IndexBTree

IndexBTree for comparison (re-exported from schema for convenience here).

Variables

This section is empty.

Functions

func Hash

func Hash(db *schema.Database) string

Hash computes a deterministic SHA-256 hash of a database schema. Two databases with identical logical schemas will produce the same hash, regardless of introspection order.

Types

type Change

type Change struct {
	Type        ChangeType
	Schema      string // PG schema name
	ObjectName  string // table, view, function, etc.
	Detail      string // human-readable description
	SQL         string // the DDL statement
	Destructive bool   // true for drops
}

Change represents a single schema change.

type ChangeType

type ChangeType int

ChangeType classifies a schema change.

const (
	CreateSchema ChangeType = iota
	DropSchema
	CreateExtension
	DropExtension
	CreateEnum
	AlterEnum // add values
	DropEnum
	CreateSequence
	AlterSequence
	DropSequence
	CreateTable
	DropTable
	AddColumn
	DropColumn
	AlterColumn
	AddConstraint // PK, unique, check
	DropConstraint
	AddForeignKey
	DropForeignKey
	CreateIndex
	DropIndex
	CreateView
	DropView
	CreateMaterializedView
	DropMaterializedView
	CreateFunction
	DropFunction
	CreateTrigger
	DropTrigger
	SetComment
	DropComment
)

type Plan

type Plan struct {
	FromHash string
	ToHash   string
	Changes  []*Change
}

Plan is an ordered list of changes with state hashes.

func Diff

func Diff(current, desired *schema.Database) *Plan

Diff compares the current database state against the desired state and returns an ordered list of changes needed to reach the desired state.

func (*Plan) HasDestructive

func (p *Plan) HasDestructive() bool

HasDestructive returns true if any change is destructive.

Jump to

Keyboard shortcuts

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