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 ¶
- func AffectedResources(changes []Change) []schema.Collection
- func ConfirmCounts(expected, actual []Report) error
- func Description(report Report) string
- func Process(changes []Change, reports []Report, resource schema.Collection, ...) (store.Values, bool, error)
- func RequireEmpty(reports []Report) error
- func RequireTransform(before, after schema.Snapshot) error
- func ValidateClear(changes []Change) error
- type Change
- type Container
- type PayloadChange
- type Report
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 ¶
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 ¶
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 ¶
RequireEmpty admits a development kind change only when every affected current value and retained snapshot is empty at the synchronization boundary.
func RequireTransform ¶
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 ¶
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 ¶
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
AppliesTo reports whether stored documents of resource can hold the change.
type PayloadChange ¶
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.