diff

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package diff provides the CompareModuleSchemas function which compares module schemas and their types and generates a structured diff. This diff can be used to check compatibility between different versions of a module schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnumTypeDiff

type EnumTypeDiff struct {
	// Name is the name of the enum type.
	Name string

	// AddedValues is a list of values that were added.
	AddedValues []schema.EnumValueDefinition

	// RemovedValues is a list of values that were removed.
	RemovedValues []schema.EnumValueDefinition

	// ChangedValues is a list of values whose numeric values were changed.
	ChangedValues []EnumValueDefinitionDiff

	// OldNumericKind is the numeric kind used to represent the enum values numerically in the old enum type.
	// It will be empty if the kind did not change.
	OldNumericKind schema.Kind

	// NewNumericKind is the numeric kind used to represent the enum values numerically in the new enum type.
	// It will be empty if the kind did not change.
	NewNumericKind schema.Kind
}

EnumTypeDiff represents the difference between two enum types.

func (EnumTypeDiff) Empty

func (e EnumTypeDiff) Empty() bool

Empty returns true if the enum type diff has no changes.

func (EnumTypeDiff) HasCompatibleChanges

func (e EnumTypeDiff) HasCompatibleChanges() bool

HasCompatibleChanges returns true if the diff contains only compatible changes. The only supported compatible change is adding values.

func (EnumTypeDiff) KindChanged

func (e EnumTypeDiff) KindChanged() bool

type EnumValueDefinitionDiff

type EnumValueDefinitionDiff struct {
	// Name is the name of the enum value.
	Name string

	// OldValue is the old numeric value of the enum value.
	OldValue int32

	// NewValue is the new numeric value of the enum value.
	NewValue int32
}

EnumValueDefinitionDiff represents the difference between two enum values definitions.

type FieldDiff

type FieldDiff struct {
	// Name is the name of the field.
	Name string

	// OldKind is the old kind of the field. It will be InvalidKind if there was no change.
	OldKind schema.Kind

	// NewKind is the new kind of the field. It will be InvalidKind if there was no change.
	NewKind schema.Kind

	// OldNullable is the old nullable property of the field.
	OldNullable bool

	// NewNullable is the new nullable property of the field.
	NewNullable bool

	// OldReferencedType is the name of the old referenced type.
	// It will be empty if the field is not a referenceable type or if there was no change.
	OldReferencedType string

	// NewReferencedType is the name of the new referenced type.
	// It will be empty if the field is not a referenceable type or if there was no change.
	NewReferencedType string
}

FieldDiff represents the difference between two fields. The KindChanged, NullableChanged, and ReferenceableTypeChanged methods can be used to determine what specific changes were made to the field.

func (FieldDiff) Empty

func (d FieldDiff) Empty() bool

Empty returns true if the field diff has no changes.

func (FieldDiff) KindChanged

func (d FieldDiff) KindChanged() bool

KindChanged returns true if the field kind changed.

func (FieldDiff) NullableChanged

func (d FieldDiff) NullableChanged() bool

NullableChanged returns true if the field nullable property changed.

func (FieldDiff) ReferenceableTypeChanged added in v0.4.0

func (d FieldDiff) ReferenceableTypeChanged() bool

ReferenceableTypeChanged returns true if the referenced type changed.

type FieldsDiff

type FieldsDiff struct {
	// Added is a list of fields that were added.
	Added []schema.Field

	// Changed is a list of fields that were changed.
	Changed []FieldDiff

	// Removed is a list of fields that were removed.
	Removed []schema.Field

	// OldOrder is the order of fields in the old list. It will be empty if the order has not changed.
	OldOrder []string

	// NewOrder is the order of fields in the new list. It will be empty if the order has not changed.
	NewOrder []string
}

FieldsDiff represents the difference between two lists of fields. Fields will be compared based on name first, and then if there is any difference in ordering that will be reported in OldOrder and NewOrder. If there is any order change, the OrderChanged method will return true. If fields were only added or removed but the order otherwise didn't change, then the OldOrder and NewOrder will still be empty.

func (FieldsDiff) Empty

func (d FieldsDiff) Empty() bool

Empty returns true if the field diff has no changes.

func (FieldsDiff) OrderChanged

func (d FieldsDiff) OrderChanged() bool

OrderChanged returns true if the field order changed.

type ModuleSchemaDiff

type ModuleSchemaDiff struct {
	// AddedStateObjectTypes is a list of object types that were added.
	AddedStateObjectTypes []schema.StateObjectType

	// ChangedStateObjectTypes is a list of object types that were changed.
	ChangedStateObjectTypes []StateObjectTypeDiff

	// RemovedStateObjectTypes is a list of object types that were removed.
	RemovedStateObjectTypes []schema.StateObjectType

	// AddedEnumTypes is a list of enum types that were added.
	AddedEnumTypes []schema.EnumType

	// ChangedEnumTypes is a list of enum types that were changed.
	ChangedEnumTypes []EnumTypeDiff

	// RemovedEnumTypes is a list of enum types that were removed.
	RemovedEnumTypes []schema.EnumType
}

ModuleSchemaDiff represents the difference between two module schemas.

func CompareModuleSchemas

func CompareModuleSchemas(oldSchema, newSchema schema.ModuleSchema) ModuleSchemaDiff

CompareModuleSchemas compares an old and a new module schemas and returns the difference between them. If the schemas are equivalent, the Empty method of the returned ModuleSchemaDiff will return true.

Indexer implementations can use these diffs to perform automatic schema migration. The specific supported changes that a specific indexer supports are defined by that indexer implementation. However, as a general rule, it is suggested that indexers support the following changes to module schemas: - Adding object types - Adding enum types - Adding nullable value fields to object types - Adding enum values to enum types

These changes are officially considered "compatible" changes, and the HasCompatibleChanges method of the returned ModuleSchemaDiff will return true if only compatible changes are present. Module authors can use the above guidelines as a reference point for what changes are generally considered safe to make to a module schema without breaking existing indexers.

func (ModuleSchemaDiff) Empty

func (m ModuleSchemaDiff) Empty() bool

func (ModuleSchemaDiff) HasCompatibleChanges

func (m ModuleSchemaDiff) HasCompatibleChanges() bool

HasCompatibleChanges returns true if the diff contains only compatible changes. Compatible changes are changes that are generally safe to make to a module schema without breaking existing indexers and indexers should aim to automatically migrate to such changes. See the CompareModuleSchemas function for a list of changes that are considered compatible.

type StateObjectTypeDiff added in v0.3.0

type StateObjectTypeDiff struct {
	// Name is the name of the object type.
	Name string

	// KeyFieldsDiff is the difference between the key fields of the object type.
	KeyFieldsDiff FieldsDiff

	// ValueFieldsDiff is the difference between the value fields of the object type.
	ValueFieldsDiff FieldsDiff
}

StateObjectTypeDiff represents the difference between two object types. The Empty method of KeyFieldsDiff and ValueFieldsDiff can be used to determine if there were any changes to the key fields or value fields.

func (StateObjectTypeDiff) Empty added in v0.3.0

func (o StateObjectTypeDiff) Empty() bool

Empty returns true if the object type diff has no changes.

func (StateObjectTypeDiff) HasCompatibleChanges added in v0.3.0

func (o StateObjectTypeDiff) HasCompatibleChanges() bool

HasCompatibleChanges returns true if the diff contains only compatible changes. The only supported compatible change is adding nullable value fields.

Jump to

Keyboard shortcuts

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