validate

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteSpec

func WriteSpec(path string, spec *Spec) error

WriteSpec writes a spec to a YAML file.

Types

type Change

type Change struct {
	Kind    ChangeKind
	Table   string
	Subject string // column/index name, or empty for table-level changes
	Detail  string // e.g. "TEXT→VARCHAR"
}

Change is a single atomic schema or data change.

func (Change) String

func (c Change) String() string

type ChangeKind

type ChangeKind string

ChangeKind describes what kind of change was observed.

const (
	KindTableAdded      ChangeKind = "table added"
	KindTableRemoved    ChangeKind = "table removed"
	KindColumnAdded     ChangeKind = "column added"
	KindColumnRemoved   ChangeKind = "column removed"
	KindColumnChanged   ChangeKind = "column type changed"
	KindIndexAdded      ChangeKind = "index added"
	KindIndexRemoved    ChangeKind = "index removed"
	KindDataRowsChanged ChangeKind = "row count out of range"
)

type ColumnSpec

type ColumnSpec struct {
	Name string `yaml:"name" json:"name"`
	Type string `yaml:"type" json:"type,omitempty"`
}

type DataSpec

type DataSpec map[string]TableDataSpec

type IndexSpec

type IndexSpec struct {
	Name   string `yaml:"name"   json:"name"`
	Unique bool   `yaml:"unique" json:"unique,omitempty"`
}

type Result

type Result struct {
	Passed     bool
	Confirmed  []Change // expected and found
	Unexpected []Change // found but not expected
	Missing    []Change // expected but not found
}

Result is the outcome of a validation run.

func Validate

func Validate(d *diff.Result, spec *Spec) *Result

Validate compares a diff result against a spec and returns a Result.

type SchemaSpec

type SchemaSpec struct {
	AddedTables    []string      `yaml:"added_tables"    json:"added_tables,omitempty"`
	RemovedTables  []string      `yaml:"removed_tables"  json:"removed_tables,omitempty"`
	ModifiedTables []TableChange `yaml:"modified_tables" json:"modified_tables,omitempty"`
}

type Spec

type Spec struct {
	Version     int        `yaml:"version"     json:"version"`
	Description string     `yaml:"description"  json:"description,omitempty"`
	Schema      SchemaSpec `yaml:"schema"       json:"schema"`
	Data        DataSpec   `yaml:"data"         json:"data,omitempty"`
}

Spec is the expectation file loaded from YAML or JSON.

func LoadSpec

func LoadSpec(path string) (*Spec, error)

LoadSpec reads a YAML or JSON expectation file.

func SpecFromDiff

func SpecFromDiff(d *diff.Result, description string) *Spec

SpecFromDiff generates a Spec from an actual diff result. Used by `litescope validate init` to bootstrap the expectation file.

type TableChange

type TableChange struct {
	Table          string       `yaml:"table"            json:"table"`
	AddedColumns   []ColumnSpec `yaml:"added_columns"    json:"added_columns,omitempty"`
	RemovedColumns []ColumnSpec `yaml:"removed_columns"  json:"removed_columns,omitempty"`
	AddedIndexes   []IndexSpec  `yaml:"added_indexes"    json:"added_indexes,omitempty"`
	RemovedIndexes []IndexSpec  `yaml:"removed_indexes"  json:"removed_indexes,omitempty"`
}

type TableDataSpec

type TableDataSpec struct {
	MinRows *int64 `yaml:"min_rows" json:"min_rows,omitempty"`
	MaxRows *int64 `yaml:"max_rows" json:"max_rows,omitempty"`
}

Jump to

Keyboard shortcuts

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