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

fieldchange

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fieldchange owns schema-addressed field-kind recovery for development and the matching fail-closed admission for immutable migration planning.

A block definition is compared once: a kind change inside it is one change, counted and cleared in every stored block of the definition, however many placements the block graph gives it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AffectedResources

func AffectedResources(changes []Change) []schema.Collection

AffectedResources returns the resources whose stored documents can hold a change, in order of first appearance.

func ConfirmCounts

func ConfirmCounts(expected, actual []Report) error

ConfirmCounts runs inside the clearing transaction. Changed counts require a new confirmation, so writes made while the developer was answering cannot silently enlarge the confirmed loss.

func Description

func Description(report Report) string

Description is a stable address without any application value.

func Process

func Process(changes []Change, reports []Report, resource schema.Collection, values store.Values, snapshot, clear bool) (store.Values, bool, error)

Process counts one document per changed field and, when clear is true, removes precisely that field at every schema-declared occurrence. Null and absent values need no recovery. Unrelated JSON/plugin properties are opaque. values are a stored document of resource in the old schema.

func RequireEmpty

func RequireEmpty(reports []Report) error

RequireEmpty admits a development kind change only when every affected current value and retained snapshot is empty at the synchronization boundary.

func RequireTransform

func RequireTransform(before, after schema.Snapshot) error

RequireTransform rejects offline schema-only plans: there is no database to prove the old address is empty. Destructive approval cannot replace a transform.

func ValidateClear

func ValidateClear(changes []Change) error

ValidateClear refuses clearing that would remove more than the changed values, bypass a framework lifecycle, or leave a required value empty.

Types

type Change

type Change struct {
	// Resource holds a change of a resource's own field. It is zero for a
	// change inside a block definition.
	Resource schema.Collection
	// Block names the definition of a change inside one; Containers and the
	// fields are then relative to the definition, and the change applies to
	// every stored block of it in Resources.
	Block string
	// Localized limits a definition change to blocks stored beneath a
	// localized ancestor (true) or not (false). Nil applies to both.
	Localized *bool
	// Resources are the resources whose stored values can hold the
	// definition's blocks, in the old schema.
	Resources  []schema.Collection
	Before     schema.Field
	After      schema.Field
	Containers []Container
	// Payload is set when the changed field is inside Before's embedded plugin
	// tree. Before and After are then the unchanged plugin field.
	Payload *PayloadChange
	// contains filtered or unexported fields
}

Change binds one field to its unchanged containing fields in the old schema. Block identifies a block discriminator on the immediately preceding container.

func Detect

func Detect(before, after schema.Snapshot) []Change

Detect compares stored fields at the same literal address. A kind change is compatible only when every value the old kind can store is read identically and remains valid under the new kind; a plugin or relationship's semantic meaning cannot be inferred from JSON shape.

Each resource's own fields are compared, then each block definition both schemas place beneath a resource they share, once in each localization scope. A changed field inside a definition placed in an embedded plugin tree is a change of the stored plugin field that holds the tree.

func (Change) AppliesTo added in v0.15.0

func (change Change) AppliesTo(resource schema.StableID) bool

AppliesTo reports whether stored documents of resource can hold the change.

func (Change) Roots added in v0.15.0

func (change Change) Roots(resource schema.Collection) []schema.Field

Roots returns the top-level fields of resource whose stored values the change reads and clears.

func (Change) TopLevel added in v0.15.0

func (change Change) TopLevel() bool

TopLevel reports a change of a resource's own top-level field.

type Container

type Container struct {
	Field schema.Field
	Block string
}

type PayloadChange

type PayloadChange struct {
	Path   string
	Before schema.Field
	After  schema.Field
}

PayloadChange is a kind change of a field declared by a plugin field's embedded tree, addressed as block.field within the embedded block definition.

type Report

type Report struct {
	ResourceID   schema.StableID
	ResourceSlug schema.CollectionSlug
	// Block names the block definition of a change inside it, whose Path is
	// relative to the definition; ResourceID and ResourceSlug are then empty.
	Block string
	// Path is the stored field whose values are counted and cleared.
	Path string
	// Payload names a changed field inside the embedded plugin tree stored at
	// Path. Adapters do not interpret plugin values, so the documents counted
	// are those with any stored value at Path.
	Payload   string
	Before    string
	After     string
	Documents int
	Snapshots int
}

Report describes one field-kind change and the persisted values whose interpretation would change. Counts include trash and all retained snapshots, and count each document once even for an array or localized field. Reports never carry document payloads.

func Reports

func Reports(changes []Change) []Report

Jump to

Keyboard shortcuts

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