Help us shape the future of Go! Take the 2026 Go Developer Survey

compare

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package compare diffs the schemas of two live connections and turns a reviewed selection of the differences into an applyable patch. Every comparison and patch is one tracked run, recorded to history with its result.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaSummary

func SchemaSummary(schema migrate.Schema) map[string]int

SchemaSummary counts a SQL Server migration snapshot's objects by kind.

func SnapshotSummary

func SnapshotSummary(snapshot review.Snapshot) (map[string]int, error)

SnapshotSummary counts a PostgreSQL or SQLite snapshot's objects by kind.

Types

type Object

type Object struct {
	Kind     string       `json:"kind"`
	Name     migrate.Name `json:"name"`
	Status   string       `json:"status"`
	Before   string       `json:"before,omitempty"`
	After    string       `json:"after,omitempty"`
	Language string       `json:"language"`
	Changes  []string     `json:"changes"`
}

Object is one changed schema object with its definition on each side: module SQL, a JSON table snapshot (SQL Server) or an HCL block (Postgres, SQLite). Before is empty for an added object and After for a deleted one.

type Options

type Options struct {
	Reference string   `json:"reference"`
	Target    string   `json:"target"`
	Schemas   []string `json:"schemas,omitempty"`
	// Run names this run: its clicky group id and its history record id.
	Run string `json:"run"`
	// ConnectionsDir resolves connection:// references.
	ConnectionsDir string `json:"-"`
	// History records the run and its result.
	History *history.Store `json:"-"`
}

Options names the two sides. Reference is the desired schema; Target is the database the patch brings in line with it.

type Patch

type Patch struct {
	Dialect   string          `json:"dialect"`
	Artifact  json.RawMessage `json:"artifact"`
	SQL       string          `json:"sql"`
	Hash      string          `json:"hash"`
	Acks      []string        `json:"acks"`
	Selection []string        `json:"selection"`
}

func BuildPatch

func BuildPatch(ctx context.Context, opts PatchOptions) (Patch, error)

BuildPatch re-inspects both sides, refuses when the differences changed since they were reviewed, and plans only the selected changes.

type PatchOptions

type PatchOptions struct {
	Options
	Selection []string `json:"select"`
	DiffHash  string   `json:"diffHash"`
	// Comparison is the recorded comparison run the selection was reviewed in,
	// when there is one.
	Comparison string `json:"comparison,omitempty"`
}

type Result

type Result struct {
	Dialect   string           `json:"dialect"`
	Reference string           `json:"reference"`
	Target    string           `json:"target"`
	Schemas   []string         `json:"schemas"`
	Changes   []migrate.Change `json:"changes"`
	Steps     []Step           `json:"steps"`
	Objects   []Object         `json:"objects"`
	// DiffHash binds a patch to the exact differences that were reviewed.
	DiffHash string `json:"diffHash"`
}

func Compare

func Compare(ctx context.Context, opts Options) (Result, error)

Compare inspects both sides and plans every difference.

type Step

type Step struct {
	Changes []string `json:"changes"`
	SQL     string   `json:"sql"`
}

Jump to

Keyboard shortcuts

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