contract

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidLockMode

func ValidLockMode(m string) bool

ValidLockMode returns true if m is a recognized lock mode.

Types

type Contract

type Contract struct {
	ID          int64             `json:"id" db:"id"`
	ServiceName string            `json:"service_name" db:"service_name"`
	TableName   string            `json:"table_name" db:"table_name"`
	Schema      model.TableSchema `json:"schema"`
	SchemaJSON  string            `json:"-" db:"schema_json"`
	LockedAt    time.Time         `json:"locked_at" db:"locked_at"`
	PromotedAt  *time.Time        `json:"promoted_at,omitempty" db:"promoted_at"`
}

Contract represents a locked schema snapshot for a single table within a service.

type DriftItem

type DriftItem struct {
	Type        DriftType `json:"type"`
	Category    string    `json:"category"` // "column_added", "column_removed", "column_renamed", "type_changed", "nullable_changed", "table_removed"
	TableName   string    `json:"table_name"`
	ColumnName  string    `json:"column_name,omitempty"`
	OldValue    string    `json:"old_value,omitempty"`
	NewValue    string    `json:"new_value,omitempty"`
	Description string    `json:"description"`
}

DriftItem describes a single difference between the locked and live schemas.

type DriftReport

type DriftReport struct {
	ServiceName   string      `json:"service_name"`
	TableName     string      `json:"table_name"`
	HasDrift      bool        `json:"has_drift"`
	HasBreaking   bool        `json:"has_breaking"`
	AdditiveCount int         `json:"additive_count"`
	BreakingCount int         `json:"breaking_count"`
	Items         []DriftItem `json:"items"`
	LockedAt      time.Time   `json:"locked_at"`
	CheckedAt     time.Time   `json:"checked_at"`
}

DriftReport summarizes all differences between a locked contract and the live schema.

func DiffTable

func DiffTable(serviceName string, locked, live model.TableSchema, lockedAt time.Time) DriftReport

DiffTable compares a locked schema contract against the live schema and returns a drift report classifying each difference as additive or breaking.

type DriftType

type DriftType string

DriftType classifies the severity of a schema change.

const (
	// DriftAdditive means a new column or table was added. Safe for consumers.
	DriftAdditive DriftType = "additive"
	// DriftBreaking means a column was renamed, removed, or had its type changed.
	DriftBreaking DriftType = "breaking"
)

type LockMode

type LockMode string

LockMode controls how Faucet handles schema drift for a service.

const (
	// LockModeNone disables contract locking. Live schema = live API.
	LockModeNone LockMode = "none"
	// LockModeAuto locks on first introspection. Additive changes auto-promote;
	// breaking changes are blocked and the locked contract shape is served.
	LockModeAuto LockMode = "auto"
	// LockModeStrict requires explicit promotion for ALL changes, even additive.
	LockModeStrict LockMode = "strict"
)

type ServiceDriftReport

type ServiceDriftReport struct {
	ServiceName   string        `json:"service_name"`
	LockMode      LockMode      `json:"lock_mode"`
	TotalTables   int           `json:"total_tables"`
	DriftedTables int           `json:"drifted_tables"`
	BreakingCount int           `json:"breaking_count"`
	Tables        []DriftReport `json:"tables"`
}

ServiceDriftReport summarizes drift across all locked tables in a service.

func DiffSchema

func DiffSchema(serviceName string, contracts []Contract, live *model.Schema, lockMode LockMode) ServiceDriftReport

DiffSchema compares all locked contracts for a service against the live schema.

Jump to

Keyboard shortcuts

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