verdict

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 2 modules, 1 package

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 verdict is the engine's structured outcome contract: every migrate invocation ends in exactly one verdict — executed natively, refused with a typed reason and, where one exists, a safer native idiom, or failed during execution with the executor's stable outcome code and a disclosure of what committed before the failure. Refusals use a distinct exit code from operational errors. This type is the seam a future orchestrator adapter maps onto SchemaBot's ExecutionModeBlocked.

Index

Constants

View Source
const (
	// ExitCodeRefused is the process exit code for refusal. Exit 0 remains
	// exclusive to online-safe success and exit 1 to operational failure.
	ExitCodeRefused = 2
	// ExitCodeAcceptedBlocking marks committed execution without an online-
	// safety guarantee; it cannot be confused with online-safe exit 0.
	ExitCodeAcceptedBlocking = 3
)
View Source
const (
	// ClassCapabilityBoundary means the engine has no implemented safe route.
	ClassCapabilityBoundary = Class(refusal.ClassCapabilityBoundary)
	// ClassNoOnlineSafetyProblem means another owner should run the work.
	ClassNoOnlineSafetyProblem Class = "no-online-safety-problem"
	// ClassByDesign means pg-sprite permanently refuses the form.
	ClassByDesign = Class(refusal.ClassByDesign)
	// ClassEnvironmental means the current run environment blocked the work.
	ClassEnvironmental = Class(refusal.ClassEnvironmental)
	// ClassInvariantViolation reports incoherent engine state.
	ClassInvariantViolation = Class(refusal.ClassInvariantViolation)
)

Variables

View Source
var ErrAcceptedBlocking = errors.New("executed without online safety")

ErrAcceptedBlocking is returned after an accepted-blocking verdict is printed so the entry point can map it to ExitCodeAcceptedBlocking.

View Source
var ErrInvalidAcceptedBlocking = errors.New("invalid accepted-blocking verdict")

ErrInvalidAcceptedBlocking reports an incomplete accepted-blocking verdict.

View Source
var ErrRefused = errors.New("refused")

ErrRefused is the sentinel the CLI returns after printing a refusal, a refusal verdict or a lint report with error findings, so the entry point can map it to ExitCodeRefused.

Functions

func AcceptedBlockingDecision added in v0.3.3

func AcceptedBlockingDecision(r Refusal) (eligible, decided bool)

AcceptedBlockingDecision reports eligibility and whether the refusal key has an explicit decision. Completeness tests use decided to reject additions to the refusal vocabulary that have not been classified here.

func AcceptedBlockingEligible added in v0.3.3

func AcceptedBlockingEligible(r Refusal) bool

AcceptedBlockingEligible reports whether a typed refusal is in the closed accepted-blocking registry. Unknown combinations fail closed.

func IndentDetail added in v0.5.8

func IndentDetail(detail string) string

IndentDetail is a verdict's Detail as the text renderings print it: a detail of several lines keeps its later lines under its first.

Types

type Cause

type Cause string

Cause narrows a refusal reason to the typed discriminator automation branches on without parsing prose: which budget fired under ReasonBudgetExceeded, or which parent shape was refused under ReasonUnsupportedPartitionedParent. The accepted-blocking registry keys on it, so a cause is part of the refusal identity, not a rendering detail. A failed verdict carries a cause only to narrow its Code the same way: which measure crossed the slot lag ceiling under slot-lag-exceeded. It is no refusal identity there; Refusal() rejects a failed verdict whatever its cause.

const (
	// CauseNone is the zero cause for verdicts whose reason has no narrower
	// discriminator.
	CauseNone Cause = ""
	// CauseLockBudget: the lock was not granted within lock_timeout; nothing
	// was executed.
	CauseLockBudget Cause = "lock-budget"
	// CauseStatementBudget: the statement ran past statement_timeout and was
	// cancelled; the change needs a rewrite.
	CauseStatementBudget Cause = "statement-budget"
	// CauseParentBlockingIndexBuild identifies a blocking index build on a
	// partitioned parent.
	CauseParentBlockingIndexBuild Cause = "parent-blocking-index-build"
	// CauseParentConcurrentIndexBuild identifies a concurrent index build on
	// a partitioned parent.
	CauseParentConcurrentIndexBuild Cause = "parent-concurrent-index-build"
	// CauseParentIndexAdoption identifies index adoption on a partitioned parent.
	CauseParentIndexAdoption Cause = "parent-index-adoption"
	// CauseParentNotValidForeignKey identifies a NOT VALID foreign key on a
	// partitioned parent.
	CauseParentNotValidForeignKey Cause = "parent-not-valid-foreign-key"
	// CauseParentConcurrentIndexDrop identifies a concurrent drop of an
	// index of a partitioned parent, which PostgreSQL does not support.
	CauseParentConcurrentIndexDrop Cause = "parent-concurrent-index-drop"
	// CauseCopyAndSwapNotEnabled: the statement routes to the copy-and-swap
	// backend, which the caller has not opted into; nothing was read or
	// executed. The route is in preview, so it runs only when the policy
	// opens it.
	CauseCopyAndSwapNotEnabled Cause = "copy-and-swap-not-enabled"
	// CauseCopyAndSwapRunStopped: the table has a copy-and-swap run that
	// stopped short of done, and the statement is not the one it records;
	// nothing was executed. The stopped run is finished by running its own
	// statement again, or discarded by a copy-and-swap run started over
	// under the restart acknowledgement.
	CauseCopyAndSwapRunStopped Cause = "copy-and-swap-run-stopped"
	// CauseSlotLagStreamBehind narrows a failed slot-lag-exceeded verdict:
	// the WAL the run's stream had yet to confirm was over the ceiling, so
	// the stream fell behind the source's writes. The slot keeps that WAL,
	// so a resume under the same ceiling is refused as resume-slot-backlog.
	// The token is decode.SlotLagStreamBehind's.
	CauseSlotLagStreamBehind Cause = "stream-behind"
	// CauseSlotLagWALRetained narrows a failed slot-lag-exceeded verdict:
	// the slot kept more WAL than the ceiling for longer than the server
	// takes to release it while the stream kept up — a transaction on the
	// source holding the WAL, or a write rate the ceiling cannot hold. The
	// token is decode.SlotLagWALRetained's.
	CauseSlotLagWALRetained Cause = "wal-retained"
	// CauseSlotLagWALRetainedHardLimit narrows a failed slot-lag-exceeded
	// verdict: the slot kept more than the hard multiple of the ceiling
	// before the grace ran out, while the stream kept up; the same family
	// and remedy as CauseSlotLagWALRetained. The token is
	// decode.SlotLagWALRetainedHardLimit's.
	CauseSlotLagWALRetainedHardLimit Cause = "wal-retained-hard-limit"
	// CauseChangedForeignKey: under ReasonDeclarativeForeignKey, the plan
	// drops a foreign key it changes under the same name on a partitioned
	// table before the new key is added, because the server refuses a
	// NOT VALID foreign key there and the two cannot share one statement.
	// Declaring the changed key under a new name adds it before the old one
	// is dropped.
	CauseChangedForeignKey Cause = "changed-foreign-key"
	// CauseColumnFirstForeignKey: under ReasonDeclarativeForeignKey, the plan
	// drops a foreign key ahead of the key it adds or validates because it
	// also retypes a column, or drops one beside an added column that may
	// rewrite the table, and such a plan runs its drops first. A new name for
	// the key does not help; applying the column change on its own first,
	// and the foreign key change after it, does.
	CauseColumnFirstForeignKey Cause = "column-first-foreign-key"
	// CauseUndeclarableForeignKey: under ReasonDeclarativeForeignKey, the
	// plan drops a live foreign key a desired file cannot declare, one into
	// another schema or one from a table to itself through a standalone
	// unique index, so the diff plans its drop whatever the file says. The
	// imperative front door removes it.
	CauseUndeclarableForeignKey Cause = "undeclarable-foreign-key"
	// CausePinnedRefusedPreview: under ReasonPlanFingerprintMismatch, the
	// pinned fingerprint is the one a desired-state dry run gives its refused
	// preview of a destructive plan, which no run executes. Nothing changed
	// since the review; the operator pinned the wrong value, and the detail
	// names the plan's own fingerprint to pin instead.
	CausePinnedRefusedPreview Cause = "pinned-refused-preview"
	// CauseAddColumnProbeLocked: under ReasonBackendUnavailable, every
	// operation the statement routes off the native path is a column add
	// whose catalog-only proof met a lock another session held, which the
	// probe does not wait for. Nothing was executed; planning the same
	// statement again once the lock is released can prove the add runs in
	// place, so the refusal is environmental rather than a missing backend.
	CauseAddColumnProbeLocked Cause = "add-column-probe-locked"
)

The causes a verdict can carry, grouped by the reason or code they narrow.

type Class added in v0.3.3

type Class string

Class identifies the routing category of a refusal. The classes an engine cause can take are declared once, in the core's pkg/refusal, and carried here under the same token, so an adapter converts a cause's refusal.Class to a verdict Class with a plain conversion and nothing can spell the two apart; no-online-safety-problem is the verdict's own, since it describes a statement that never reached the engine.

func Classes added in v0.3.3

func Classes() []Class

Classes returns the closed set of refusal classes.

func ParseClass added in v0.3.3

func ParseClass(value string) (Class, error)

ParseClass validates a refusal class token.

type IndexUsage added in v0.4.0

type IndexUsage struct {
	// IdxScans is the cumulative count of scans of the index since
	// StatsReset, or since the index was created if that is later; for a
	// partitioned index, the sum over its leaf indexes.
	IdxScans int64 `json:"idx_scan"`
	// LastIdxScan is when the server last recorded a scan; absent when it
	// recorded none, and always on PostgreSQL 14 and 15. In UTC.
	LastIdxScan *time.Time `json:"last_idx_scan,omitempty"`
	// StatsReset is when the database's statistics were last reset; absent
	// when the server reports no reset. In UTC.
	StatsReset *time.Time `json:"stats_reset,omitempty"`
	// ReadAt is the server's clock when the evidence was read. In UTC.
	ReadAt time.Time `json:"read_at"`
	// Unique reports whether the index enforces uniqueness, a guarantee the
	// drop would also discard.
	Unique bool `json:"unique"`
	// Partitions is the number of leaf indexes of a partitioned index, whose
	// scans IdxScans sums; absent for an index that is not partitioned.
	Partitions *int `json:"partitions,omitempty"`
	// TrackCounts is false when the server was counting no scans, so a zero
	// IdxScans proves nothing.
	TrackCounts bool `json:"track_counts"`
	// TrackCountsOffBySetting is true when a saved ALTER ROLE or ALTER
	// DATABASE setting turns track_counts off, so the scans of those
	// sessions are missing from IdxScans.
	TrackCountsOffBySetting bool `json:"track_counts_off_by_setting"`
}

IndexUsage is how the server pg-sprite is connected to has seen an index used, read when a DROP INDEX is refused for want of the destructive acknowledgement. It describes that one server only: every replica keeps its own counters, so an index this server never scans may still serve a replica's reads.

func (IndexUsage) Summary added in v0.4.0

func (u IndexUsage) Summary() string

Summary renders the evidence on one line for the verdict's text form.

type LockHolder added in v0.5.8

type LockHolder struct {
	// PID is the holder's backend process ID.
	PID uint32 `json:"pid"`
	// Table is the schema-qualified table it held the lock on.
	Table string `json:"table"`
	// Held is how long the wait saw it holding the lock, which is at most
	// the wait itself; its transaction may have held it for far longer.
	Held time.Duration `json:"held_ns"`
	// State is the session's pg_stat_activity state, such as "idle in
	// transaction" or "active". It and the fields after it are absent when
	// the connected role cannot see that session, the session ended before
	// it was described, or the read that describes it failed.
	State string `json:"state,omitempty"`
	// ApplicationName is the session's application_name; also absent when
	// the client set none. Any client chooses its own, up to the server's
	// name length, so a host escapes it like other user text before it
	// renders it into markdown, a table cell, or a comment.
	ApplicationName string `json:"application_name,omitempty"`
	// TransactionAge is how long the session's transaction had been open.
	TransactionAge time.Duration `json:"transaction_age_ns,omitempty"`
	// QueryAge is how long ago the session's current or last query started.
	QueryAge time.Duration `json:"query_age_ns,omitempty"`
}

LockHolder is the session that held a lock on a table through the whole of a step's wait outside the lock queue, so the step, or a copy-and-swap run's cutover, ended without requesting its own lock. It is the machine-readable twin of the holder the verdict's detail names, so a host can show who held the table without parsing prose. The holder's query text is never carried: it can hold row values.

type Outcome

type Outcome string

Outcome is what happened to the submitted change.

const (
	// OutcomeExecuted means the change ran and committed natively within
	// its budgets.
	OutcomeExecuted Outcome = "executed-natively"
	// OutcomeExecutedWithoutOnlineSafety means the operator accepted a typed
	// blocking refusal and the statement committed under explicit budgets.
	OutcomeExecutedWithoutOnlineSafety Outcome = "executed-without-online-safety"
	// OutcomeExecutedViaCopyAndSwap means the change committed through the
	// copy-and-swap route: a shadow table built under the changed shape,
	// filled and verified against the source, then swapped into the
	// source's name. The source table was never rewritten in place.
	OutcomeExecutedViaCopyAndSwap Outcome = "executed-via-copy-and-swap"
	// OutcomeRefused means the change was not executed; Reason says why.
	OutcomeRefused Outcome = "refused"
	// OutcomeFailed means execution was attempted and failed: an
	// operational error, not a refusal — the process still exits 1. Code
	// carries the executor's stable outcome code, and for a mid-sequence
	// failure FailedStep and ExecutedSQL disclose the failed step and the
	// committed prefix whose state remains, so automation can distinguish
	// "nothing happened" from "partial state left behind".
	OutcomeFailed Outcome = "failed"
)

The outcomes a migrate run can end in.

type Owner added in v0.3.3

type Owner string

Owner identifies who owns work that has no online-safety problem.

const (
	// OwnerDataChangeRunner owns DML and backfills.
	OwnerDataChangeRunner Owner = "data-change-runner"
	// OwnerDeclarativeFrontDoor owns desired catalog convergence.
	OwnerDeclarativeFrontDoor Owner = "declarative-front-door"
	// OwnerDirectOperator means the operator runs the work directly.
	OwnerDirectOperator Owner = "direct-operator"
	// OwnerProvisioning owns access-control and replication provisioning.
	OwnerProvisioning Owner = "provisioning"
)

func Owners added in v0.3.3

func Owners() []Owner

Owners returns the closed set of refusal owners.

func ParseOwner added in v0.3.3

func ParseOwner(value string) (Owner, error)

ParseOwner validates a refusal owner token.

type PartitionedIndexFault added in v0.5.8

type PartitionedIndexFault struct {
	// Index is the invalid index the failed build left under the partition
	// index's name, schema-qualified with every identifier quoted, as
	// DROP INDEX CONCURRENTLY takes it (for example
	// "billing"."orders_id_uq_p16397").
	Index string `json:"index"`
	// Partition is the partition Index sits on, whose rows broke it,
	// schema-qualified with every identifier quoted. A partition may live
	// in another schema than its parent, so it is the partition's own
	// schema. Empty when the run could not prove Index its own: the entry
	// is then placed on no table.
	Partition string `json:"partition,omitempty"`
	// Resumable is true when the run proved Index its own leftover: once
	// the rows are corrected, running the same statement again drops it,
	// builds it again, and resumes from the partitions already done. When
	// false, Index is inspected before any removal
	// (docs/invalid-index-recovery.md), and the rerun follows once it is
	// dealt with.
	Resumable bool `json:"resumable"`
}

PartitionedIndexFault is what a partitioned table's index build left when one partition's rows broke the index it was building there: duplicate values under a unique index, or an index expression raising on a row. It is the machine-readable twin of the partition and index the verdict's detail names, and its presence on a failed data-fault verdict is what tells that verdict apart from a copy-and-swap data fault (Abandoned) and from a native concurrent build's (FailedStep): there is no run to restart, so the remedy is to correct the rows and run the same statement again. The build keeps the parent's invalid index and the partition indexes built before the stop either way.

type Reason

type Reason string

Reason is the typed cause of a refusal. Reasons are flat kebab-case tokens — they are what automation switches on; prose belongs in Detail.

const (
	// ReasonNone is the zero reason carried by an executed verdict.
	ReasonNone Reason = ""
	// ReasonUnsupportedStatement: only ALTER TABLE is supported.
	ReasonUnsupportedStatement Reason = "unsupported-statement"
	// ReasonIndexStatement: index maintenance has a native safe idiom
	// (CONCURRENTLY) and is never attempted here.
	ReasonIndexStatement Reason = "index-statement"
	// ReasonTableTooLarge: the size guard skipped the optimistic attempt.
	ReasonTableTooLarge Reason = "not-native-safe-table-too-large"
	// ReasonInsufficientPrivileges: the connected role lacks the access
	// the change needs; Detail names the exact missing GRANT (see
	// docs/engine-role.md).
	ReasonInsufficientPrivileges Reason = "insufficient-privileges"
	// ReasonUnsupportedPartitionedParent: the plan has a step pg-sprite
	// cannot run on a partitioned parent: adopting an index as a
	// constraint, a NOT VALID foreign key before PostgreSQL 18, a
	// concurrent DROP INDEX of the parent's index, or a blocking index
	// build, which is what a forced CREATE INDEX takes. An unforced CREATE
	// INDEX is not one of these, because it runs as the partitioned index
	// build.
	ReasonUnsupportedPartitionedParent Reason = "unsupported-partitioned-parent"
	// ReasonBudgetExceeded: the optimistic attempt exceeded its lock or
	// statement budget and was cancelled.
	ReasonBudgetExceeded Reason = "not-native-safe-budget-exceeded"
	// ReasonRewriteRequired: the submitted form is not safe to run as
	// submitted — it blocks the table, or it is a rename that breaks the
	// application instances still using the old name — and must run as a
	// safer sequence, but the planner has none to substitute (a
	// multi-operation statement, a pattern it cannot build, or a rename,
	// whose safe sequence spans application deploys). Running the
	// submitted form would falsify the plan's own reason, so the engine
	// refuses instead unless the override names the table.
	ReasonRewriteRequired Reason = "not-native-safe-rewrite-required"
	// ReasonBackendUnavailable: the change routes to an execution strategy
	// that has no carrying path for the operation in this build (a
	// copy-and-swap rewrite the shadow-table engine does not carry yet).
	ReasonBackendUnavailable Reason = "backend-unavailable"
	// ReasonDestructiveChange: the change discards live data or structure —
	// a dropped column, constraint, index, or NOT NULL. The imperative
	// front door runs such a statement only when the destructive
	// acknowledgement names its table; desired-state execution refuses a
	// destructive plan whole and has no acknowledgement for it, so the
	// imperative statement is the way to run a reviewed destructive change.
	ReasonDestructiveChange Reason = "destructive-change"
	// ReasonPlanFingerprintMismatch: the plan recomputed at execution time
	// does not carry the fingerprint the caller pinned, so the plan a
	// reviewer approved is not the plan that would execute; nothing runs.
	ReasonPlanFingerprintMismatch Reason = "plan-fingerprint-mismatch"
	// ReasonCreateCollision: the create plan's target name is already
	// occupied — a relation or standalone type took it after the plan was
	// derived — so the greenfield create cannot run; the caller re-derives
	// the plan against the live catalog rather than assuming the
	// occupant's shape.
	ReasonCreateCollision Reason = "create-collision"
	// ReasonDeclarativeForeignKey: the desired-state plan drops a foreign
	// key it changes under the same name before the new one is added, on a
	// partitioned table or beside a dropped or retyped column, which would
	// leave writes checked against no key until the new one is added, or a
	// key a desired file cannot declare, one into another schema or one from
	// a table to itself through a standalone unique index, which the plan
	// drops whatever the file says. The plan still shows the change; the
	// imperative front door runs the drop.
	ReasonDeclarativeForeignKey Reason = "declarative-foreign-key"
	// ReasonCopyAndSwapRefused: the change routes to copy-and-swap and the
	// route's own gates declined it — the preflight found a table shape or
	// an environment it cannot run against, or the engine refused mid-run
	// to keep an invariant. Cause carries the route's own refusal token
	// (see docs/refusal-classes.md), Class its routing class.
	ReasonCopyAndSwapRefused Reason = "copy-and-swap-refused"
)

The refusal reasons Phase 1 can emit.

func Reasons added in v0.2.0

func Reasons() []Reason

Reasons returns the closed set of non-zero Reason values. It is part of the verdict contract: the tokens are what automation switches on, so the set changes only deliberately, every token is pinned by test, and every token has a row in docs/cli-output-examples.md's refusal-reason table.

type Refusal added in v0.3.3

type Refusal struct {
	// contains filtered or unexported fields
}

Refusal is proof that a class, reason, and owner form a valid refusal: the fields are unexported and the only constructor validates them, so a refusal that reaches a renderer through WithRefusal has been classified. The classification registries in pkg/plan and pkg/migrate mint these; a refusal site never names a class on its own.

func ByDesign added in v0.3.3

func ByDesign(reason Reason) Refusal

ByDesign classifies a refusal of a form pg-sprite will never run.

func CapabilityBoundary added in v0.3.3

func CapabilityBoundary(reason Reason) Refusal

CapabilityBoundary classifies a refusal of work the engine may learn to do.

func Environmental added in v0.3.3

func Environmental(reason Reason) Refusal

Environmental classifies a refusal the run environment caused.

func InvariantViolation added in v0.3.3

func InvariantViolation(reason Reason) Refusal

InvariantViolation classifies a refusal of a state this build should not have produced.

func NewRefusal added in v0.3.3

func NewRefusal(class Class, reason Reason, owner Owner) (Refusal, error)

NewRefusal validates and constructs a refusal proof. It rejects a reason outside Reasons(), a class outside Classes(), an owner outside Owners(), and an owner that is absent when the class is no-online-safety-problem or present when it is not.

func NoOnlineSafetyProblem added in v0.3.3

func NoOnlineSafetyProblem(reason Reason, owner Owner) Refusal

NoOnlineSafetyProblem classifies a refusal of work that is safe to run elsewhere and names who runs it.

func (Refusal) Cause added in v0.3.3

func (r Refusal) Cause() Cause

Cause returns the typed cause that narrows the refusal, when one exists.

func (Refusal) Class added in v0.3.3

func (r Refusal) Class() Class

Class returns the refusal's validated class.

func (Refusal) IsZero added in v0.3.3

func (r Refusal) IsZero() bool

IsZero reports whether r was never constructed through NewRefusal.

func (Refusal) Owner added in v0.3.3

func (r Refusal) Owner() Owner

Owner returns the refusal's validated owner; empty unless the class is no-online-safety-problem.

func (Refusal) Reason added in v0.3.3

func (r Refusal) Reason() Reason

Reason returns the refusal's validated reason.

func (Refusal) Site added in v0.3.3

func (r Refusal) Site() RefusalSite

Site returns the typed refusal site that narrows the refusal, when one exists.

func (Refusal) WithCause added in v0.3.3

func (r Refusal) WithCause(cause Cause) Refusal

WithCause returns r narrowed by a typed cause.

func (Refusal) WithSite added in v0.3.3

func (r Refusal) WithSite(site RefusalSite) Refusal

WithSite returns r narrowed by a typed refusal site.

type RefusalCause added in v0.5.8

type RefusalCause struct {
	// Cause is the typed cause, in the vocabulary of Verdict.Cause.
	Cause Cause `json:"cause"`
	// Class is the routing class the cause declares.
	Class Class `json:"class"`
	// Detail is the fact behind the cause, naming the objects involved.
	Detail string `json:"detail"`
	// NextStep is the one thing the operator does about the cause.
	NextStep string `json:"next_step"`
	// Advisory marks a cause found by a preview rather than decided by the
	// check that refused: an environment cause listed beside a
	// copy-and-swap shape refusal, read without the proof the environment
	// check takes. The environment check itself runs, and may refuse
	// again, once the shape passes. False for every cause that refused.
	Advisory bool `json:"advisory,omitempty"`
}

RefusalCause is one of several causes behind a refusal: its typed cause, the routing class that cause declares, the fact behind it, and what the operator does about it.

type RefusalSite added in v0.3.3

type RefusalSite string

RefusalSite is a typed refusal-site discriminator used when a reason spans statement shapes but has no underlying cause.

const (
	// RefusalSiteIndexSingleRelation is the plain one-relation DROP INDEX,
	// REINDEX INDEX, or REINDEX TABLE gate site.
	RefusalSiteIndexSingleRelation RefusalSite = "index-statement-single-relation"
	// RefusalSiteIndexOther is a multi-relation DROP INDEX, a DROP INDEX with
	// CASCADE, or a REINDEX scope that does not identify one relation.
	RefusalSiteIndexOther RefusalSite = "index-statement-other"
)

type RefusedStatement added in v0.5.7

type RefusedStatement struct {
	// Statement is the statement's 1-based position in the file.
	Statement int `json:"statement"`
	// Line and Column locate the statement's first token, both 1-based,
	// with the column counted in characters.
	Line   int `json:"line"`
	Column int `json:"column"`
	// Detail is why the statement is refused.
	Detail string `json:"detail"`
}

RefusedStatement is one statement a desired file refused and where it starts in the file.

func (RefusedStatement) String added in v0.5.7

func (r RefusedStatement) String() string

String names the refused statement by where it starts and why it is refused.

type SlotLag added in v0.5.8

type SlotLag struct {
	// Slot is the replication slot the stopped run keeps.
	Slot string `json:"slot"`
	// RetainedBytes is the WAL the slot kept on the volume.
	RetainedBytes int64 `json:"retained_bytes"`
	// UnconfirmedBytes is the share of RetainedBytes the run's stream had
	// yet to confirm.
	UnconfirmedBytes int64 `json:"unconfirmed_bytes"`
	// CeilingBytes is the ceiling the run ran under.
	CeilingBytes int64 `json:"ceiling_bytes"`
	// SuggestedCeilingBytes is the ceiling to resume under: twice the
	// retained WAL, never below twice CeilingBytes, rounded up to a power
	// of two. A resume is refused while the slot holds more unconfirmed WAL
	// than its ceiling, and this one leaves the resumed stream room to read
	// through what the slot holds.
	SuggestedCeilingBytes int64 `json:"suggested_ceiling_bytes"`
	// Resumable is true when the checkpoint row and the slot stay, so
	// running the same statement again resumes the run rather than
	// starting it over.
	Resumable bool `json:"resumable"`
}

SlotLag is the reading of a live copy-and-swap run's replication slot when the slot lag ceiling stopped the run, all sizes in bytes of WAL. Every field is present, zero included.

type StatisticsRefresh added in v0.4.0

type StatisticsRefresh struct {
	// Columns are the columns the statement retyped, in statement order.
	// On a copy-and-swap verdict the ANALYZE covers every column of the
	// new table, and Columns is empty for a statement that retyped none.
	Columns []string `json:"columns"`
	// Refreshed reports that the ANALYZE committed.
	Refreshed bool `json:"refreshed"`
	// Pending is the ANALYZE still to run; empty when Refreshed.
	Pending string `json:"pending,omitempty"`
}

StatisticsRefresh is the outcome of analyzing a table a committed change left without planner statistics: a native type change, which deletes the retyped columns' statistics, or a copy-and-swap, whose swapped-in table is a new relation with none of its own. The change stays committed whether or not the refresh ran, so a refresh still owed leaves the verdict executed and names the ANALYZE to run.

type Verdict

type Verdict struct {

	// Outcome is what happened.
	Outcome Outcome `json:"outcome"`
	// Reason is the typed refusal cause; empty when executed.
	Reason Reason `json:"reason,omitempty"`
	// Class identifies how a consumer routes a refusal.
	Class Class `json:"class,omitempty"`
	// Owner identifies who owns work with no online-safety problem.
	Owner Owner `json:"owner,omitempty"`
	// Cause narrows the refusal reason to its typed discriminator: the
	// budget that fired, or the partitioned-parent shape refused. Empty
	// when the reason has none. Preserved on an accepted-blocking verdict.
	// On a failed verdict it narrows Code instead: under slot-lag-exceeded,
	// the measure that crossed the ceiling (stream-behind, wal-retained, or
	// wal-retained-hard-limit). Empty on every other failed verdict.
	Cause Cause `json:"cause,omitempty"`
	// Code is the executor's stable outcome code (executor.OutcomeCode)
	// carried by a failed verdict — flat kebab-case, part of the executor's
	// report contract. It stays a plain string here so this contract
	// package does not depend on the executor. Empty unless Outcome is
	// OutcomeFailed.
	Code string `json:"code,omitempty"`
	// SQLState is the SQLSTATE of the server error that failed the
	// statement, when the server rejected it; empty when the failure
	// was not a server error. Automation can branch on it, as on Code,
	// to tell a constraint the rows break (23514) from an object that
	// does not exist (42883). Empty unless Outcome is OutcomeFailed.
	SQLState string `json:"sqlstate,omitempty"`
	// ServerError is that server error's primary message, for display.
	// It leaves out the server's DETAIL line, but the primary message of
	// a data fault (SQLSTATE class 22) can still name a row's value, as
	// in `invalid input syntax for type integer: "abc"`. Empty exactly
	// when SQLState is.
	ServerError string `json:"server_error,omitempty"`
	// FailedStep is the 1-based position of the sequence step that failed,
	// matching the numbering the planner's partial-failure contracts use;
	// zero when the failure was not a mid-sequence one (a single-statement
	// attempt that fails before its COMMIT rolls back and commits nothing).
	// When Code is an outcome-unknown code, the step's own COMMIT may have
	// landed: its state is unknown, not failed.
	FailedStep int `json:"failed_step,omitempty"`
	// FailedStepSQL is the failed step's statement — the step the planner's
	// partial-failure contract says a retry resumes from. When Code is an
	// outcome-unknown code, the step may have committed, so a retry cannot
	// be assumed to resume here until the catalog is inspected.
	FailedStepSQL string `json:"failed_step_sql,omitempty"`
	// Attempts is how many bounded attempts ran before a lock-budget
	// refusal, or before a copy-and-swap run stopped because its cutover
	// spent every lock attempt (code budget-lock-exceeded, or
	// execution-failed when the last attempt ended on the server's lock
	// timeout or deadlock refusal), so automation can tell an exhausted
	// bounded retry from a single cancelled attempt; zero for every other
	// verdict, including one whose code outranks the spent cutover and a
	// live copy-and-swap run that a reader or writer outlasted before it
	// made any cutover attempt.
	Attempts int `json:"attempts,omitempty"`
	// Statement is the submitted SQL.
	Statement string `json:"statement"`
	// Table is the target table (schema-qualified when the statement was),
	// when the statement has one.
	Table string `json:"table,omitempty"`
	// Detail is the human explanation: why refused, or what committed.
	Detail string `json:"detail,omitempty"`
	// Causes is set on a copy-and-swap-refused verdict the route's
	// preflight refused for the table's shape: every shape cause the table
	// has, in the order the preflight decides them, so the first is Cause
	// and carries Class. One run reports them all, each with the objects
	// behind it and one next step. On a live migrate.Run (one that decodes
	// WAL) the shape causes are followed by the environment causes a
	// read-only preview finds, each marked Advisory. Empty for every other verdict,
	// an environment refusal of the same route included.
	Causes []RefusalCause `json:"causes,omitempty"`
	// WritesBlocked is true on an executed, failed, or refused copy-and-swap
	// verdict whose run blocked the table's writes (offline mode,
	// --block-writes): the write fence went on, and every write that reached
	// it was refused with SQLSTATE 55006. On a failed verdict it is set when
	// the stopped run's fence still stands, read from the catalog after the
	// stop, or when the run was abandoned after its fence went on, which
	// Detail says took it off again; on a refused verdict it is set only
	// when the catalog shows the stopped run's fence still standing. A
	// blocked-writes run that stopped before its fence went on reports
	// false, since the table kept taking writes, and so does one whose
	// checkpoint row remains with no fence standing — the table dropped and
	// created again, or the fence dropped or disabled by hand — since the
	// table takes writes. A catalog read that fails after the stop reports
	// the fence, and its error rides with the verdict. False for every
	// other verdict, including a live run's.
	WritesBlocked bool `json:"writes_blocked,omitempty"`
	// SwapLSN is set on an executed-via-copy-and-swap verdict whose run
	// committed the swap itself: the server's WAL insert position, in
	// PostgreSQL's pg_lsn text form (for example "0/1A2B3C8"), read inside
	// the swap transaction while its ACCESS EXCLUSIVE lock kept every other
	// session off the table, right before it committed. A write to the
	// table that committed below this position is in the retained source
	// and was carried into the new table; an orchestrator can use it to
	// state "writes after this position exist only in the new table".
	// Compare it with another position as pg_lsn, not as text. Empty when
	// the run did not hear its own swap commit: a run resumed after the
	// swap had committed, or one that lost its connection and learned of
	// the commit from the catalog. Empty for every other verdict.
	SwapLSN string `json:"swap_lsn,omitempty"`
	// Verification is set on an executed-via-copy-and-swap verdict whose
	// run verified the shadow before its swap: the figures of that
	// verification pass. Detail states the rows, chunks, and settled
	// chunks too; Unsettled and Carried are only here. Nil when
	// the pass compared no chunk — a run resumed after its swap had
	// committed makes no pass, and an empty table has nothing to compare —
	// and for every other verdict.
	Verification *Verification `json:"verification,omitempty"`
	// RetainedTable is set on an executed-via-copy-and-swap verdict whose
	// run kept the retained source (--keep-old, CopySwapOptions.KeepOld):
	// the name the source table bears after the swap, schema-qualified with
	// every identifier quoted, as DROP TABLE takes it (for example
	// "public"."_pgsprite_c74da4a21f58f903_old"). Dropping it ends the
	// rollback window. Empty for every other verdict, including a run that
	// dropped the retained source.
	RetainedTable string `json:"retained_table,omitempty"`
	// SlotLag is set on a failed verdict coded slot-lag-exceeded that
	// carries the slot's reading at the stop: the slot, its measures, the
	// ceiling it crossed, and the ceiling a resume is suggested to run
	// under, so a caller acts on the stop without parsing Detail. Nil for
	// every other verdict, and for a slot-lag-exceeded verdict whose error
	// carried no reading.
	SlotLag *SlotLag `json:"slot_lag,omitempty"`
	// RefusedStatements is set on a refused verdict for a desired file that
	// refused more than one of its statements: every one, in file order,
	// each with where it starts, so the file's author fixes them in one
	// edit. The verdict's own class, statement, and detail describe the one
	// refusal that decides the file's verdict. Empty for every other
	// verdict, including a file that refused a single statement, which the
	// verdict names.
	RefusedStatements []RefusedStatement `json:"refused_statements,omitempty"`
	// TableCreated is true on an executed verdict whose run created the
	// table, committing it in the same transaction as its row security, so
	// automation can tell a create from a run that converged a table that
	// already existed. Detail says the same for a reader. False for every
	// other verdict.
	TableCreated bool `json:"table_created,omitempty"`
	// AlreadyDetached is true on an executed verdict for a DETACH PARTITION
	// whose partition was already a table of its own with the table's
	// columns when the run read the catalog, so nothing ran. That is the
	// state an earlier run, or a concurrent detach the server finished after
	// its client went away, leaves; the catalog keeps no record of a finished
	// detach, so a same-shaped table that never was a partition reads the
	// same. ExecutedSQL is empty, and Detail says the same for a reader.
	// False for every other verdict.
	AlreadyDetached bool `json:"already_detached,omitempty"`
	// AlreadyNotNull is true on an executed verdict for a lone SET NOT NULL
	// whose column was already NOT NULL on the table and every table below
	// it, with no helper CHECK of an earlier run left, when the run read the
	// catalog, so nothing ran. ExecutedSQL is empty, and Detail says the
	// same for a reader. False for every other verdict.
	AlreadyNotNull bool `json:"already_not_null,omitempty"`
	// ExtensionSchemas is set on a verdict whose run created the table
	// from a desired file that named extension schemas: the schemas the
	// create's unqualified names also resolved against, in search order
	// after the table's schema and public. ExecutedSQL ran under that
	// search path, so a reader replaying or auditing it needs them. Empty
	// for every other verdict.
	ExtensionSchemas []string `json:"extension_schemas,omitempty"`
	// Abandoned is true on a failed copy-and-swap verdict whose run the
	// engine abandoned on a data fault: the shadow is dropped, the hold on
	// the source — write fence or replication slot — is released, and the
	// checkpoint row is deleted, so nothing remains and the corrected
	// statement runs from the beginning without any acknowledgement. A
	// copy-and-swap data-fault verdict with it false is a run whose abandon
	// did not finish: the row and the hold stand as far as the discard got,
	// and the run is started over with the restart acknowledgement. A
	// data-fault verdict that carries FailedStep is a native concurrent
	// index build that failed on the rows, not a copy-and-swap run: there
	// is no run to abandon or restart, and the build's invalid index is
	// the leftover Detail names. A data-fault verdict that carries
	// PartitionedIndexFault is a partitioned table's index build, not a
	// copy-and-swap run either. It is the field automation branches on;
	// Detail says the same for a reader.
	// False for every other verdict, including a refusal: a run whose lock
	// session is lost after its discard finished comes back as the
	// shadow-lock-lost refusal, with nothing left behind but no field to say
	// so. On RunDesired it is set on the failed entry of
	// DesiredResult.Verdicts, not on the aggregate.
	Abandoned bool `json:"abandoned,omitempty"`
	// PartitionedIndexFault is set on a failed data-fault verdict of a
	// partitioned table's index build that stopped on one partition's rows:
	// the partition and the invalid index the build left there. It is the
	// field automation branches on to send the verdict to "correct the
	// rows, then run the same statement again" rather than to a restart;
	// Detail says the same for a reader. Nil for every other verdict.
	PartitionedIndexFault *PartitionedIndexFault `json:"partitioned_index_fault,omitempty"`
	// SaferIdiom is a native alternative to the refused statement, when one
	// exists (e.g. CREATE INDEX CONCURRENTLY, ADD CONSTRAINT ... NOT VALID).
	SaferIdiom string `json:"safer_idiom,omitempty"`
	// Guidance is the typed manual path for a rewrite-required refusal,
	// drawn from the suggest contract's Guidance vocabulary
	// (docs/suggest-report.md), the same value the plan report's statement
	// carries, for a destructive-change refusal whose statement drops a
	// column and adds it back under the same name, or for a
	// copy-and-swap-pk-unsupported refusal of a table with no primary key
	// (add-integer-primary-key). Detail states the steps
	// for a human; Guidance is the key an automated caller branches on.
	// Empty for every other verdict.
	Guidance suggest.Guidance `json:"guidance,omitempty"`
	// DependentViews names the views and materialized views that read the
	// column a refused statement retypes or drops, each schema-qualified
	// with every identifier quoted, sorted: the objects to drop or redefine
	// before the change can run. The same list the plan report's refused
	// decision carries, present whenever one blocks the change, whatever
	// the refusal's reason, and empty otherwise.
	DependentViews []string `json:"dependent_views,omitempty"`
	// DependentPolicies names the row-level security policies that read
	// the column a refused statement retypes or drops, each rendered
	// "policy" ON "schema"."table" with every identifier quoted, sorted:
	// the policies to drop before the change and recreate after it. The
	// same list the plan report's refused decision carries, present
	// whenever one blocks the change, whatever the refusal's reason, and
	// empty otherwise.
	DependentPolicies []string `json:"dependent_policies,omitempty"`
	// DependentTriggers names the triggers whose UPDATE OF list or WHEN
	// condition names the column a refused statement retypes or drops,
	// each rendered "trigger" ON "schema"."table" with every identifier
	// quoted, sorted. The same list the plan report's refused decision
	// carries, present whenever one blocks the change, whatever the
	// refusal's reason, and empty otherwise.
	DependentTriggers []string `json:"dependent_triggers,omitempty"`
	// DependentRules names the rewrite rules that read the column a
	// refused statement retypes or drops, each rendered "rule" ON
	// "schema"."table" with every identifier quoted, sorted. The same list
	// the plan report's refused decision carries, present whenever one
	// blocks the change, whatever the refusal's reason, and empty
	// otherwise.
	DependentRules []string `json:"dependent_rules,omitempty"`
	// DependentPublications names the publications whose column list or
	// row filter for the table names the column a refused statement
	// retypes or drops, each rendered "publication" with its identifier
	// quoted, sorted. The same list the plan report's refused decision
	// carries, present whenever one blocks the change, whatever the
	// refusal's reason, and empty otherwise.
	DependentPublications []string `json:"dependent_publications,omitempty"`
	// DependentGeneratedColumns names the generated columns whose
	// expression reads the column a refused statement retypes or drops,
	// each rendered "schema"."table"."column" with every identifier quoted,
	// sorted. The same list the plan report's refused decision carries,
	// present whenever one blocks the change, whatever the refusal's
	// reason, and empty otherwise.
	DependentGeneratedColumns []string `json:"dependent_generated_columns,omitempty"`
	// PartitionKeyTables names the partitioned tables whose partition key
	// includes the column a refused statement retypes or drops, each
	// schema-qualified with every identifier quoted, sorted. The same list
	// the plan report's partition-key decision carries. Empty for every
	// other verdict.
	PartitionKeyTables []string `json:"partition_key_tables,omitempty"`
	// NotNullFromType is the added column's type, as the statement spells
	// it with every identifier quoted, when a not-null-without-default
	// refusal's column is NOT NULL only because that type, a domain, makes
	// it so. The same value the plan report's refused decision carries.
	// Empty for every other verdict.
	NotNullFromType string `json:"not_null_from_type,omitempty"`
	// ConstrainedType is the added column's type, as the statement spells
	// it with every identifier quoted, when a backend-unavailable refusal
	// is forced by adding a column of a domain with constraints, which
	// PostgreSQL checks against every row by rewriting the table. The same
	// value the plan report's type-rewrite decision carries. Empty for
	// every other verdict.
	ConstrainedType string `json:"constrained_type,omitempty"`
	// ColumnLimit is how many column numbers the table had free before a
	// column-limit refusal's change, and the tables that have used the
	// most numbers: the ones to rebuild. The same value the plan report's
	// column-limit decision carries. Nil for every other verdict.
	ColumnLimit *preflight.ColumnNumbers `json:"column_limit,omitempty"`
	// ExecutedSQL is the ordered SQL the engine actually ran and committed.
	// On an executed verdict it is the substituted safer native sequence
	// (empty when the submitted form ran as-is — a non-empty value is what
	// tells automation a substitution happened — or when nothing ran
	// because AlreadyDetached or AlreadyNotNull is set). On a failed verdict
	// it is
	// the committed prefix that remains: empty means nothing is known to
	// have committed — and nothing at all did, unless Code is an
	// outcome-unknown code, in which case the failed step itself (or the
	// single statement) may have committed and the catalog decides.
	ExecutedSQL []string `json:"executed_sql,omitempty"`
	// Forced reports that --force overrode the engine's routing: the
	// submitted form ran as-is instead of a safer substitution or a
	// strategy refusal. It is the machine-readable audit record of the
	// override.
	Forced bool `json:"forced,omitempty"`
	// AllowedDestructive reports that --allow-destructive acknowledged the
	// data the statement discards: a statement the destructive-change gate
	// would refuse went on through the engine's other gates instead. It is
	// the machine-readable audit record of the acknowledgement, set on
	// every verdict the acknowledged statement ends in.
	AllowedDestructive bool `json:"allowed_destructive,omitempty"`
	// BlockingPassthrough marks execution of an operator-accepted refusal.
	BlockingPassthrough bool `json:"blocking_passthrough,omitempty"`
	// LockTimeout is the explicit lock-acquisition budget.
	LockTimeout string `json:"lock_timeout,omitempty"`
	// StatementTimeout is the explicit statement execution budget.
	StatementTimeout string `json:"statement_timeout,omitempty"`
	// StatisticsRefresh reports the ANALYZE a committed type change owes
	// the planner, and on a copy-and-swap verdict the ANALYZE of the new
	// table the run made before its swap; nil when a native statement
	// retyped no column, and when a copy-and-swap run only finished a swap
	// an earlier run made.
	StatisticsRefresh *StatisticsRefresh `json:"statistics_refresh,omitempty"`
	// IndexUsage is the live usage evidence of the index a destructive-change
	// refusal of an accepted DROP INDEX would have dropped; nil for every
	// other verdict.
	IndexUsage *IndexUsage `json:"index_usage,omitempty"`
	// LockHolder is the session that held the table through a step's or a
	// copy-and-swap cutover's whole wait outside the lock queue, so the
	// lock was never requested; nil for every verdict that did not end on
	// such a holder.
	LockHolder *LockHolder `json:"lock_holder,omitempty"`
	// contains filtered or unexported fields
}

Verdict is the structured outcome of one migrate invocation.

func (Verdict) JSON

func (v Verdict) JSON() (string, error)

JSON renders the verdict as a single JSON object.

func (Verdict) Refusal added in v0.3.3

func (v Verdict) Refusal() (Refusal, error)

Refusal reconstructs the classified refusal a refused verdict carries, so a caller that aggregates verdicts into its own result propagates the class and owner through the same one path instead of copying fields. It fails on a verdict that is not refused, or whose reason, class, and owner do not validate together — a verdict this build cannot have produced. An in-process verdict returns its full proof, re-validated the same way and checked against the exported refusal fields, so a proof that never passed the constructors, or fields rewritten after WithRefusal, cannot reach an eligibility decision. A verdict decoded from JSON reconstructs class, reason, owner, and cause, but cannot recover its refusal site; site-keyed eligibility therefore fails closed after JSON decoding, while cause-keyed eligibility is decidable from the JSON fields.

func (Verdict) String

func (v Verdict) String() string

String renders the verdict for humans.

func (Verdict) WithAcceptedBlocking added in v0.3.3

func (v Verdict) WithAcceptedBlocking(r Refusal, lockTimeout, statementTimeout time.Duration) (Verdict, error)

WithAcceptedBlocking returns an executed verdict that retains the accepted refusal identity and explicit non-zero execution budgets.

func (Verdict) WithRefusal added in v0.3.3

func (v Verdict) WithRefusal(r Refusal) Verdict

WithRefusal returns v as a refused verdict carrying r's reason, class, owner, cause, and full in-process proof. It is the one path from a classified refusal onto the verdict contract, so a site that forgets to classify has no Reason to set.

type Verification added in v0.5.5

type Verification struct {
	// Rows is the number of source rows the pass hashed.
	Rows int64 `json:"rows"`
	// Chunks is the number of chunks the pass compared.
	Chunks int `json:"chunks"`
	// Settled is the number of chunks a live pass found differing in its
	// sweep and then settled key by key against the stream; zero for a run
	// that blocked writes.
	Settled int `json:"settled"`
	// Unsettled is the number of chunks a live pass could settle neither
	// way, every one of them holding keys the pass left for the swap; zero
	// whenever Carried is.
	Unsettled int `json:"unsettled"`
	// Carried is the number of keys the live pass left for the swap to
	// compare under its lock, the keys of the unsettled chunks that never
	// held still; the swap compared each and found it equal, or it would
	// have refused. The count only: the keys themselves are row data.
	Carried int `json:"carried"`
}

Verification is what a copy-and-swap run's verification pass compared before the swap: the source against its shadow, chunk by chunk, up to the copy's complete watermark. Every field is present, zero included, so a reader tells a pass that settled nothing from one that did not say.

Jump to

Keyboard shortcuts

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