diff

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diff compares two schemas object by object and lists what it takes to turn one into the other. It reads what the loader holds of the database state and nothing else: `-- sqlshape:` directives, problems and analysis results are not schema.

Expressions compare by their deparsed text, so the two sides should be in the same form: both loaded from schema text, or both canonical (dump.Canonical / dump.Load). A rename is not recognized: it shows as a drop and an add, and an intent declaration is the place to say otherwise.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Props

func Props(s *schema.Schema, obj any) map[string]string

Props are the comparable properties of a relation, column, constraint, index, rule, function or trigger: two objects with equal Props are the same to Compare.

func Signature

func Signature(s *schema.Schema, f *schema.Function) string

Signature is how a function is named: schema.name(input types).

func UserTypes

func UserTypes(s *schema.Schema) map[string]UserType

UserTypes lists a schema's declared types by name (public omitted).

Types

type Change

type Change struct {
	Op   Op
	Kind string // schema, extension, enum, domain, composite, range, table, view, matview, sequence, column, constraint, index, rule, policy, rows, function, trigger, comment
	Name string // qualified as the loader prints it: public omitted; column / constraint / index / rule as <relation>.<name>; trigger as <relation>.<name>
	// Fields are the properties that differ, for Alter.
	Fields []Field
}

Change is one object added, dropped or altered.

func Compare

func Compare(a, b *schema.Schema) []Change

Compare lists the changes from a to b, sorted by kind order (dependencies first for additions: schemas, extensions, types, relations, their parts, functions, triggers, comments) then by name. Drops come in the same order; ordering for execution is the DDL generator's job.

func (Change) OrderOnly

func (c Change) OrderOnly() bool

OrderOnly reports whether a change is nothing but a relation's columns in another order: the database cannot be brought to the declared order without rebuilding the table, so apply tolerates it and reports it as a note.

func (Change) String

func (c Change) String() string

type Field

type Field struct {
	Name     string
	From, To string
}

Field is one differing property.

func RowChanges

func RowChanges(from, to *schema.Relation) []Field

RowChanges compares the seeded content of a table: the rows the target declares against the rows the source holds, by key. Each field names the key and shows the row texts (From empty for a row to insert, To empty for one to delete). A column left out of the declaration does not count, rows an additive seed does not list are not a change, and a target without a seed declares nothing about the content.

type Op

type Op byte

Op is what happens to an object.

const (
	Add   Op = '+'
	Drop  Op = '-'
	Alter Op = '~'
)

type UserType

type UserType struct {
	OID   catalog.OID
	Kind  string // enum, domain, composite, range
	Props map[string]string
}

UserType is a declared type with its comparable properties.

Jump to

Keyboard shortcuts

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