compare

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 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 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

This section is empty.

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"`
	// ResolveConnection resolves connection:// references.
	ResolveConnection dbtarget.ResolveConnection `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"`
	// Rebuilds are the dependents the changes force to be dropped and
	// re-created; each names its change in Cause and cannot be selected alone.
	Rebuilds []migrate.Change `json:"rebuilds,omitempty"`
	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