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

controlplane

package
v0.0.0-...-4aa7ecc Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package controlplane holds the state store, the lease-based scheduler and drift monitoring.

Index

Constants

View Source
const (
	AuditTargetRegister  = "target.register"
	AuditTargetBaseline  = "target.baseline"
	AuditTargetReconcile = "target.reconcile"
	AuditRunCreate       = "run.create"
	AuditRunRevert       = "run.revert"
	AuditRunResume       = "run.resume"
	AuditRunPark         = "run.park"
	AuditRunConfirm      = "run.confirm"
	AuditDriftAccept     = "drift.accept"
	AuditPlanCreate      = "plan.create"
	AuditPlanSupersede   = "plan.supersede"
	AuditRunReattach     = "run.reattach"
	AuditCheckpoint      = "checkpoint.generate"
	AuditWebhookCommand  = "webhook.command"
	AuditCredentialStore = "credential_store.register"
)

Audit actions.

View Source
const (
	OutcomeDone       = "done"
	OutcomeFailed     = "failed"
	OutcomeInFlight   = "in flight"
	OutcomeNotReached = "not reached"
)

Outcomes a journalled statement is reported under.

View Source
const (
	PlanReady      = "ready"
	PlanBound      = "bound"
	PlanSuperseded = "superseded"
)

Plan states.

View Source
const (
	StaleHistory    = "history"
	StaleSchema     = "schema"
	StaleOrder      = "order"
	StaleValidation = "validation"
	StaleContent    = "content"
)

Stale reasons carried by PlanStale.

View Source
const (
	RolloutDirect         = "direct"
	RolloutExpandContract = "expand-contract"
)

Rollout policy names.

View Source
const (
	ReasonNetwork = "network"
	ReasonTimeout = "timeout"
)

Failure classes reported in notifications and metrics.

View Source
const (
	DefaultMaxConcurrentRuns = 4
	DefaultRunTimeout        = 24 * time.Hour
)

Scheduler defaults: a long backfill on one target must not park the others, and no run may hold a slot forever.

View Source
const (
	StateQueued           = "queued"
	StateRunning          = "running"
	StateSucceeded        = "succeeded"
	StateFailed           = "failed"
	StateNeedsAttention   = "needs_attention"
	StateAwaitingContract = "awaiting_contract"
	StateReverted         = "reverted"
)

Run states.

View Source
const (
	PhaseExpand   = "expand"
	PhaseContract = "contract"
)

Run phases.

View Source
const (
	KindMigrate   = "migrate"
	KindBaseline  = "baseline"
	KindReconcile = "reconcile"
)

Run kinds.

View Source
const (
	ConfigLockTimeout      = "lock_timeout"
	ConfigStatementTimeout = "statement_timeout"
	ConfigRequirePlan      = "require_plan"
	ConfigKeepOld          = "keep_old"
	ConfigIgnoreAdopted    = "ignore_adopted_tables"
)

Target config keys holding the per-target timeouts, the plan requirement and the change-type default.

View Source
const ConfigSearchPath = "search_path"

ConfigSearchPath is the target config key holding the per-target search_path.

View Source
const DefaultBatchSize = 5000

DefaultBatchSize is how many rows a generated backfill touches per transaction when the directive is silent.

View Source
const DefaultScratchTemplate = "template0"

DefaultScratchTemplate is template0: template1 may carry an extension a non-superuser scratch role cannot add itself.

View Source
const DriftHistoryLimit = 100

DriftHistoryLimit is how many events one ListDriftEvents call returns; a caller holding that many is looking at a window, not at the history.

View Source
const JournalSchema = "godwit"

JournalSchema is where godwit's journal lives on every target, whatever the search_path is.

View Source
const MaxPageSize = 1000

MaxPageSize is the ceiling every listing clamps its caller's limit to, so one call cannot materialise a whole table.

Variables

View Source
var (
	ErrNotFound            = errors.New("not found")
	ErrLeaseLost           = errors.New("lease lost")
	ErrNotResumable        = errors.New("run is not failed or parked")
	ErrNotAwaitingContract = errors.New("run is not awaiting contract")
	ErrNotRevertable       = errors.New("run is not revertable")
	ErrBaselineRun         = errors.New("baseline runs cannot be reverted")
)

Sentinel errors.

View Source
var (
	// ErrNoSuchVersion marks a version target that names no migration in the submitted set.
	ErrNoSuchVersion = errors.New("no migration in this set has version")
	// ErrVersionTarget marks a version target the target's own history will not honour.
	ErrVersionTarget = errors.New("version target")
)
View Source
var ErrAppliedContent = errors.New("applied with different content")

ErrAppliedContent marks a file whose version is applied on the target with a different checksum.

View Source
var ErrBaselineFormat = errors.New("drift baseline predates the schema format")

ErrBaselineFormat marks a baseline taken before godwit changed what a schema snapshot describes.

View Source
var ErrCheckpoint = errors.New("checkpoint")

ErrCheckpoint marks a checkpoint godwit refuses to generate.

View Source
var ErrDesiredSchema = errors.New("desired schema failed to apply")

ErrDesiredSchema marks a desired schema the author must fix.

View Source
var ErrDirective = errors.New("godwit directive")

ErrDirective marks a directive godwit will not expand; the API reports it as invalid_argument.

View Source
var ErrDiverged = errors.New("target and ledger disagree")

ErrDiverged marks a target whose journal and the ledger cannot be reconciled without a decision only a person can take.

View Source
var ErrJournalOnSearchPath = errors.New("the target's search_path reaches godwit's journal schema")

ErrJournalOnSearchPath marks a target whose sessions resolve unqualified names against the journal schema.

View Source
var ErrMigrationFiles = errors.New("migration files failed to replay")

ErrMigrationFiles marks committed migration files that do not replay on top of the target's history.

View Source
var ErrRepeatableSchema = errors.New("repeatable migration does not build on the desired schema")

ErrRepeatableSchema marks a repeatable migration that does not build on the desired schema.

View Source
var ErrRepeatablesUnknown = errors.New("target records repeatable migrations and the request carried no migration files")

ErrRepeatablesUnknown marks a diff whose request carried no migration files while the target records repeatable migrations.

View Source
var ErrRevertPlan = errors.New("revert plan")

ErrRevertPlan marks a revert whose down side cannot be built from what the run applied.

View Source
var ErrScratchPrivileged = errors.New("scratch role can act outside its own scratch databases")

ErrScratchPrivileged marks a scratch connection whose role can act outside its own scratch databases.

View Source
var ErrValidationDisabled = errors.New("diffing against the committed files needs validation, which is disabled on this service")

ErrValidationDisabled marks a diff against the committed files on a service started with validation off.

View Source
var ErrValidationFailed = errors.New("migration failed validation")

ErrValidationFailed marks a migration the author must fix.

Functions

func AttachChanges

func AttachChanges(migs []PlanMigration, v *Validation)

AttachChanges puts what the scratch replay saw each migration do to the schema on the migration itself.

func Detect

func Detect(migs []PlanMigration, plans []engine.Plan, v Validation, obs Observation) string

Detect marks the longest prefix of migs whose effect the target already holds; otherwise returns the drift.

func ExpandDown

func ExpandDown(plans []engine.Plan, applied []RunMigration) ([]engine.Plan, error)

ExpandDown substitutes each migration's own frozen inverse from the ledger; a hand-written .down.sql has no expansion and wins untouched.

func ExpandPlan

func ExpandPlan(p engine.Plan, exp Expansion) (engine.Plan, error)

ExpandPlan rebuilds a plan from its frozen expansion; the migration keeps the checksum of the file, not of what godwit generated from it.

func ExpandUp

func ExpandUp(plans []engine.Plan, exps map[string]Expansion) ([]engine.Plan, error)

ExpandUp replaces each directive migration's body with the expansion frozen on the plan or the run.

func FilesHash

func FilesHash(files map[string]string) string

FilesHash identifies a set of submitted files independent of what is pending; the retry migration computes the same value in SQL.

func HistoryHash

func HistoryHash(applied []engine.Applied, reps []engine.Repeatable) string

HistoryHash hashes an applied set as "id checksum" lines, versions ascending then repeatables by name.

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) (int, error)

Migrate applies the control-plane schema and reports how many migrations ran; the advisory lock needs a dedicated session.

func MigrationsFromFiles

func MigrationsFromFiles(files map[string]string) ([]engine.Migration, error)

MigrationsFromFiles loads migrations from in-memory files named like on disk.

func NewHolder

func NewHolder(name string) string

NewHolder builds this process's lease identity, "<name>/<random>": a name alone collides across processes on one machine.

func ParseSearchPath

func ParseSearchPath(value string) (string, error)

ParseSearchPath validates a comma-separated list of unquoted schema names and folds it the way PostgreSQL does.

func Pending

func Pending(migs []engine.Migration, applied []engine.Applied, reps []engine.Repeatable) ([]engine.Migration, error)

Pending returns the migrations the target would run: versions it has not applied, plus repeatables whose content differs.

func PlanKey

func PlanKey(target, rollout string, pending []engine.Migration) string

PlanKey identifies a pending set on a target: the files and what the target has applied, nothing else.

func PlansFromFiles

func PlansFromFiles(files map[string]string, dir engine.Direction) ([]engine.Plan, error)

PlansFromFiles loads migration files and plans one direction; down plans come newest first.

func Policies

func Policies() map[string]RolloutPolicy

Policies returns the built-in rollout policies.

func Retired

func Retired(exps map[string]Expansion) map[string][]RetiredColumn

Retired lists every column the expansions of one run leave behind, keyed by migration.

func RunEvent

func RunEvent(r Run, typ, detail string) notify.Event

RunEvent builds the notification for a run at its current state.

func RunsBody

func RunsBody(p engine.Plan, applied AppliedSet) bool

RunsBody reports whether the executor would run the plan's statements; a down plan runs because the target holds it.

func SameStatements

func SameStatements(a, b []PlanMigration) bool

SameStatements reports whether two plans would run the same statements with the same hazards and phases.

func SetGitHubRepositories

func SetGitHubRepositories(config map[string]string, entries []string) error

SetGitHubRepositories records the repositories a GitHub App delivery may reach this target from; an empty list clears them.

func Truncate

func Truncate(plans []engine.Plan, to int64, applied AppliedSet) (keep, withheld []engine.Plan)

Truncate splits plans at a version target: versioned migrations at or below to, plus the repeatables only when nothing versioned is held back, since a repeatable declares what the whole directory produces.

func Unreconciled

func Unreconciled(obs Observation, applied AppliedSet) []string

Unreconciled names the migrations a target's journal records that no standing ledger row accounts for; an observation with no history reports none.

Types

type AppliedSet

type AppliedSet struct {
	Versions    []int64
	Repeatables map[string]string
}

AppliedSet is what a target already holds: versions the control plane ran and the content it recorded per repeatable.

func (AppliedSet) Has

func (a AppliedSet) Has(m engine.Migration) bool

Has reports whether the target already holds m: the version, or the repeatable under that content.

func (AppliedSet) Newest

func (a AppliedSet) Newest() int64

Newest is the highest version the target has applied, or zero when it has none.

type ApplyRequest

type ApplyRequest struct {
	RunID    string
	Target   string
	DSN      string
	Plans    []engine.Plan
	Opts     engine.Options
	Progress func(engine.StatementEvent)
	Record   Recorder
}

ApplyRequest is one run's worth of plans plus the effective execution options.

type AuditEntry

type AuditEntry struct {
	ID     int64
	At     time.Time
	Actor  string
	Action string
	RunID  string
	Target string
	Detail string
}

AuditEntry is one recorded mutation: who did what to which target or run.

type Baseliner

type Baseliner struct {
	// contains filtered or unexported fields
}

Baseliner marks migrations applied on a target without running them and records that as a succeeded run.

func NewBaseliner

func NewBaseliner(sched *Scheduler) *Baseliner

NewBaseliner shares the scheduler's store, credential providers and engine.

func (*Baseliner) Baseline

func (b *Baseliner) Baseline(ctx context.Context, runID, target string, migs []engine.Migration, p Provenance) error

Baseline marks migs applied on target, records run runID and snapshots the schema for drift; both sides are idempotent.

type Checkpoint

type Checkpoint struct {
	Version int64
	Name    string
	Through int64
	Covers  []string
	Body    string
}

Checkpoint is a generated checkpoint file: the schema a prefix of the migration directory produces.

func (Checkpoint) UpFile

func (c Checkpoint) UpFile() string

UpFile is the name the checkpoint is written under.

type Checkpointer

type Checkpointer struct {
	Expander *Expander
	// contains filtered or unexported fields
}

Checkpointer generates a checkpoint by replaying the files on a scratch database and rendering the schema they left as DDL.

func NewCheckpointer

func NewCheckpointer(scratch *Scratch, newID func() string) *Checkpointer

NewCheckpointer wires a Checkpointer over the scratch connection.

func (*Checkpointer) Generate

func (c *Checkpointer) Generate(ctx context.Context, files map[string]string, at int64, name string, now time.Time) (Checkpoint, error)

Generate collapses every version of files at or below at (zero takes the newest) into one checkpoint named name, and refuses unless replaying its DDL alone reproduces the same fingerprint.

type Config

type Config struct {
	Holder            string
	TTL               time.Duration
	Interval          time.Duration
	MaxAttempts       int
	MaxConcurrentRuns int
	RunTimeout        time.Duration
	Jitter            func() float64
}

Config tunes a Scheduler.

type CredentialStore

type CredentialStore struct {
	Name     string
	Address  string
	Role     string
	Mount    string
	TokenEnv string
	Targets  int
}

CredentialStore is a registered Vault a target's secret can be read from.

type DiffBase

type DiffBase int

DiffBase is the schema a desired one is compared against.

const (
	// DiffBaseLive is the target's live schema.
	DiffBaseLive DiffBase = iota
	// DiffBaseFiles is what the committed migration files produce on top of the target's recorded history.
	DiffBaseFiles
)

type Differ

type Differ struct {
	// contains filtered or unexported fields
}

Differ generates the migration between a target's live schema and a desired DDL applied on a scratch database.

func NewDiffer

func NewDiffer(scratch *Scratch, sched *Scheduler, history HistoryReplayer, newID func() string) *Differ

NewDiffer wires a Differ over the scratch connection; history is optional (nil skips drift).

func (*Differ) Diff

func (d *Differ) Diff(ctx context.Context, target, ddl string, base DiffBase, files map[string]string) (SchemaDiff, error)

Diff applies ddl on a scratch database and returns the SQL between base and it in both directions.

type Direct

type Direct struct{}

Direct applies everything at once.

func (Direct) Split

func (Direct) Split(plans []engine.Plan) ([]engine.Plan, []engine.Plan)

Split implements RolloutPolicy.

type Divergence

type Divergence struct {
	Adopt       []string
	Conflicting []string
	Unknown     []string
	Withdrawn   []string
}

Divergence is how a target's journal and the control plane's ledger differ; Adopt is repairable, everything else is not.

func Diverged

func Diverged(obs Observation, applied AppliedSet, migs []engine.Migration) Divergence

Diverged compares a target's journal with the ledger, reading the content of each migration from migs.

func (Divergence) Err

func (d Divergence) Err(target string) error

Err reports what a reconcile cannot decide on its own, or nil.

type Drift

type Drift struct {
	Target  string
	Drifted bool
	Diff    string
}

Drift is the outcome of comparing a target's live schema to its baseline.

type DriftEvent

type DriftEvent struct {
	ID         int64
	Target     string
	Diff       string
	DetectedAt time.Time
	ResolvedAt *time.Time
}

DriftEvent is one detected divergence between expected and live schema.

type DriftMonitor

type DriftMonitor struct {
	Metrics           *metrics.Metrics
	PlanRetention     time.Duration
	DeliveryRetention time.Duration
	// contains filtered or unexported fields
}

DriftMonitor periodically compares live schemas against their baselines.

func NewDriftMonitor

func NewDriftMonitor(store *Store, sched *Scheduler, eng Engine, notifier notify.Notifier, interval time.Duration, log *slog.Logger) *DriftMonitor

NewDriftMonitor wires a DriftMonitor; interval <= 0 defaults to 5 minutes.

func (*DriftMonitor) AcceptBaseline

func (m *DriftMonitor) AcceptBaseline(ctx context.Context, target string) error

AcceptBaseline records the live schema as the expected state and resolves open drift.

func (*DriftMonitor) Check

func (m *DriftMonitor) Check(ctx context.Context, target string) (Drift, error)

Check compares one target now and records the outcome.

func (*DriftMonitor) Run

func (m *DriftMonitor) Run(ctx context.Context)

Run checks all targets on every interval until ctx is done.

func (*DriftMonitor) Tick

func (m *DriftMonitor) Tick(ctx context.Context)

Tick checks every baselined target once and sweeps plans and webhook deliveries past retention.

type Engine

type Engine interface {
	Apply(ctx context.Context, req ApplyRequest) error
	MarkApplied(ctx context.Context, dsn string, migs []engine.Migration) ([]engine.Migration, error)
	Snapshot(ctx context.Context, dsn string, scope engine.SnapshotScope) (engine.Schema, error)
	Applied(ctx context.Context, dsn string) ([]engine.Applied, []engine.Repeatable, error)
	Journal(ctx context.Context, dsn string, version int64, repeatable string) ([]engine.JournalRun, error)
	Observe(ctx context.Context, dsn string, scope engine.SnapshotScope) (Observation, error)
	DataLoss(ctx context.Context, dsn string, drops []engine.Drop) ([]engine.Loss, error)
}

Engine applies plans to a target database, marks migrations applied and inspects its schema and journal.

type ExpandContract

type ExpandContract struct{}

ExpandContract holds the first destructive migration and everything after it.

func (ExpandContract) Split

func (ExpandContract) Split(plans []engine.Plan) ([]engine.Plan, []engine.Plan)

Split implements RolloutPolicy.

type Expander

type Expander struct {
	KeepOld   bool
	BatchSize int
}

Expander turns directives into statements using a catalog that already holds the target's history.

func NewExpander

func NewExpander() *Expander

NewExpander returns an Expander with godwit's defaults.

func (*Expander) Expand

func (x *Expander) Expand(ctx context.Context, conn engine.DB, m engine.Migration) (Expansion, error)

Expand renders every directive of m against conn and returns the bodies the plan freezes.

type Expansion

type Expansion struct {
	ID        string               `json:"id"`
	UpSQL     string               `json:"up_sql"`
	DownSQL   string               `json:"down_sql"`
	DownHeld  string               `json:"down_held_sql,omitempty"`
	Phase     []string             `json:"phase"`
	Batches   []*engine.BatchSpec  `json:"batches,omitempty"`
	Asserts   []*engine.AssertSpec `json:"asserts,omitempty"`
	Notes     []string             `json:"notes,omitempty"`
	Retired   []RetiredColumn      `json:"retired,omitempty"`
	Unretired []RetiredColumn      `json:"unretired,omitempty"`
	Lines     []string             `json:"lines,omitempty"`
	Hash      string               `json:"hash"`
}

Expansion is the SQL godwit generates for one migration's directives, frozen into the plan so the run applies what the pull request showed.

func (Expansion) Contract

func (e Expansion) Contract() int

Contract is the index of the first contract statement, or -1 when the expansion has one phase.

type Fleet

type Fleet struct {
	Targets    []string
	Migrations []FleetMigration
}

Fleet is the cross-target answer to "which of my databases has this migration".

type FleetFilter

type FleetFilter struct {
	Targets       []string
	FromVersion   int64
	ToVersion     int64
	NotEverywhere bool
	In            string
	NotIn         string
}

FleetFilter narrows the fleet view; a zero filter answers over every registered target.

type FleetGap

type FleetGap struct {
	Target        string
	NewestVersion int64
	Behind        bool
	Holds         bool
	OtherChecksum string
}

FleetGap is a target the entry does not stand on, with what separates it from the ones that do.

type FleetMigration

type FleetMigration struct {
	Migration  string
	Version    int64
	Name       string
	Repeatable bool
	Checkpoint bool
	Checksum   string
	On         []FleetOn
	Missing    []FleetGap
	Divergent  bool
}

FleetMigration is one migration as one content: a version standing under two checksums is two entries.

type FleetOn

type FleetOn struct {
	Target      string
	AppliedAt   time.Time
	RunID       string
	CollapsedBy string
}

FleetOn is a target standing on one migration under the entry's checksum.

type GitHubRun

type GitHubRun struct {
	RunID        string
	Repository   string
	RepositoryID int64
	Installation int64
	PullRequest  int
	Head         string
	Command      string
	Target       string
	Marker       string
	Format       string
	CheckRun     int64
	State        string
	Reverts      string
}

GitHubRun binds a run to the pull request whose command created it, so a replica that did not accept that command can still report it back.

type HistoryChange

type HistoryChange struct {
	Version    int64
	Name       string
	Repeatable bool
	At         time.Time
	RunID      string
}

HistoryChange is one migration that entered or left the target's history since a plan was taken.

func (HistoryChange) String

func (c HistoryChange) String() string

String renders the change as it appears in a stale report.

type HistoryMigration

type HistoryMigration struct {
	ID        string
	UpSQL     string
	DownSQL   string
	Expansion *Expansion
}

HistoryMigration is one standing ledger row: the pair the run carried for it and the expansion it froze.

type HistoryReplayer

type HistoryReplayer interface {
	Validate(ctx context.Context, target string, plans []engine.Plan, searchPath string) (Validation, error)
	Replay(ctx context.Context, conn engine.DB, target, searchPath string, plans []engine.Plan) error
}

HistoryReplayer rebuilds a target's recorded history on a scratch database (implemented by Validator).

type HistoryRun

type HistoryRun struct {
	Migrations []HistoryMigration
}

HistoryRun is one run's contribution to a target's history: the migrations it applied that still stand, in the order it applied them.

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

Inspector reads a target's applied versions, last run and drift baseline without changing anything.

func NewInspector

func NewInspector(sched *Scheduler) *Inspector

NewInspector shares the scheduler's store, credential providers and engine.

func (*Inspector) DataLoss

func (i *Inspector) DataLoss(ctx context.Context, name string, drops []engine.Drop) ([]engine.Loss, error)

DataLoss reports which of the drops would destroy data the target still holds.

func (*Inspector) Journal

func (i *Inspector) Journal(ctx context.Context, target, migration string) (MigrationJournal, error)

Journal reads one migration's statement journal off the target and joins it to the SQL the applying run stored.

func (*Inspector) Observe

func (i *Inspector) Observe(ctx context.Context, name string) (Observation, error)

Observe reads the target's live history and schema over one connection.

func (*Inspector) Status

func (i *Inspector) Status(ctx context.Context, name string) (TargetStatus, error)

Status lists what the target's database has applied next to the control plane's view, describing rather than refusing a target whose credential does not resolve.

type LedgerEntry

type LedgerEntry struct {
	RunID     string
	AppliedAt time.Time
	Applied   bool
	Adopted   bool
	Expansion *Expansion
	UpSQL     string
	DownSQL   string
}

LedgerEntry is what the control plane holds about one migration on one target, with the file bodies of the run that carried it.

type MigrationAttempt

type MigrationAttempt struct {
	engine.JournalRun
	Statements []MigrationStatement
}

MigrationAttempt is one godwit.runs row on the target with its statements.

type MigrationJournal

type MigrationJournal struct {
	Target       string
	Migration    string
	Attempts     []MigrationAttempt
	RunID        string
	AppliedAt    time.Time
	Adopted      bool
	RecordedOnly bool
	Unreachable  string
	BodiesSwept  bool
}

MigrationJournal is what one target recorded about one migration, from its own journal and the control plane's ledger.

type MigrationStatement

type MigrationStatement struct {
	engine.JournalStatement
	SQL      string
	NoTx     bool
	Verifier string
	Outcome  string
}

MigrationStatement is one statement of an attempt: what the target journalled, and the SQL the run executed.

type Observation

type Observation struct {
	Applied     []engine.Applied
	Repeatables []engine.Repeatable
	Definition  string
	Fingerprint string
	SearchPath  string
	At          time.Time
	Ignored     []engine.Adopted
}

Observation is a target's live migration history and schema at one moment.

func (Observation) HistoryHash

func (o Observation) HistoryHash() string

HistoryHash hashes the observed history, ascending by version then by repeatable name.

type PGEngine

type PGEngine struct {
	Metrics *metrics.Metrics
	Log     *slog.Logger
}

PGEngine is the PostgreSQL Engine; Metrics and Log are optional.

func (PGEngine) Applied

func (PGEngine) Applied(ctx context.Context, dsn string) ([]engine.Applied, []engine.Repeatable, error)

Applied implements Engine.

func (PGEngine) Apply

func (e PGEngine) Apply(ctx context.Context, req ApplyRequest) error

Apply implements Engine.

func (PGEngine) DataLoss

func (PGEngine) DataLoss(ctx context.Context, dsn string, drops []engine.Drop) ([]engine.Loss, error)

DataLoss implements Engine.

func (PGEngine) Journal

func (PGEngine) Journal(ctx context.Context, dsn string, version int64, repeatable string) ([]engine.JournalRun, error)

Journal implements Engine.

func (PGEngine) MarkApplied

func (PGEngine) MarkApplied(ctx context.Context, dsn string, migs []engine.Migration) ([]engine.Migration, error)

MarkApplied implements Engine.

func (PGEngine) Observe

func (PGEngine) Observe(ctx context.Context, dsn string, scope engine.SnapshotScope) (Observation, error)

Observe implements Engine: history and schema read over one connection.

func (PGEngine) Snapshot

func (PGEngine) Snapshot(ctx context.Context, dsn string, scope engine.SnapshotScope) (engine.Schema, error)

Snapshot implements Engine.

type Plan

type Plan struct {
	ID                string
	Target            string
	Key               string
	Rollout           string
	State             string
	HistoryHash       string
	Applied           []engine.Applied
	Repeatables       []engine.Repeatable
	SchemaFingerprint string
	SchemaDefinition  string
	SearchPath        string
	Drift             string
	Migrations        []PlanMigration
	Validated         bool
	Acked             []string
	AllowOutOfOrder   bool
	CreatedBy         string
	Source            string
	CreatedAt         time.Time
	RunID             string
	SupersededBy      string
	Expansions        map[string]Expansion
}

Plan is a stored admission result plus the observation it was taken against.

func (Plan) PathMoved

func (p Plan) PathMoved(obs Observation) bool

PathMoved reports whether the target's effective search_path changed since the plan was taken; one stored before the path was recorded never moved.

func (Plan) Pending

func (p Plan) Pending() []PlanMigration

Pending returns the migrations the plan would run; one a version target withheld is not among them.

type PlanAssert

type PlanAssert struct {
	Op    string `json:"op"`
	Kind  string `json:"kind"`
	Value string `json:"value"`
}

PlanAssert is the condition an assert statement states about the value its query returns.

type PlanBatch

type PlanBatch struct {
	Key   string `json:"key"`
	Kind  string `json:"kind"`
	Size  int    `json:"size"`
	Pause string `json:"pause,omitempty"`
}

PlanBatch describes a statement the executor runs as a resumable loop instead of once.

type PlanDiff

type PlanDiff struct {
	Added   []HistoryChange
	Removed []HistoryChange
	Schema  []string
	Path    string
}

PlanDiff is how a target moved away from a plan's observation.

func StaleDiff

func StaleDiff(p Plan, obs Observation) PlanDiff

StaleDiff compares a plan's observation with a fresh one; a repeatable recorded under new content counts as removed and added.

func (PlanDiff) Explained

func (d PlanDiff) Explained(baseline, fingerprint string) bool

Explained reports whether every change since the plan was made by godwit itself; baseline is the stored snapshot fingerprint.

func (PlanDiff) Reason

func (d PlanDiff) Reason() string

Reason names what refuses the bind: history when a migration moved without a run, schema otherwise.

type PlanHazard

type PlanHazard struct {
	Code      string `json:"code"`
	Detail    string `json:"detail"`
	Recipe    string `json:"recipe,omitempty"`
	Object    string `json:"object,omitempty"`
	Attribute string `json:"attribute,omitempty"`
}

PlanHazard is one hazard on a planned statement.

type PlanMigration

type PlanMigration struct {
	Version    int64           `json:"version"`
	Name       string          `json:"name"`
	Repeatable bool            `json:"repeatable,omitempty"`
	Checksum   string          `json:"checksum"`
	Applied    bool            `json:"applied"`
	Phase      string          `json:"phase"`
	Statements []PlanStatement `json:"statements"`

	AlreadyApplied bool   `json:"already_applied,omitempty"`
	Effect         string `json:"effect,omitempty"`
	Note           string `json:"note,omitempty"`
	Withheld       bool   `json:"withheld,omitempty"`

	Changes []engine.ObjectChange `json:"changes,omitempty"`

	// Stored inverted: a plan written before the field existed keeps counting every hazard rather than none.
	Skipped bool `json:"skipped,omitempty"`

	Checkpoint bool  `json:"checkpoint,omitempty"`
	Through    int64 `json:"collapses_through,omitempty"`

	Directives []string `json:"directives,omitempty"`
	Expanded   bool     `json:"expanded,omitempty"`
	Notes      []string `json:"notes,omitempty"`
	Expansion  string   `json:"expansion,omitempty"`
}

PlanMigration is one migration of a stored plan with its phase and applied flag.

func BuildPlanMigrations

func BuildPlanMigrations(rollout string, plans []engine.Plan, applied AppliedSet, exps map[string]Expansion) []PlanMigration

BuildPlanMigrations records what admission decided for each plan: phase under the rollout and whether it is applied.

func WithheldMigrations

func WithheldMigrations(plans []engine.Plan, applied AppliedSet) []PlanMigration

WithheldMigrations reports what a version target kept out of the run, so a plan says what it is not doing.

func (PlanMigration) ID

func (m PlanMigration) ID() string

ID identifies the migration in plan keys and reports.

type PlanRequired

type PlanRequired struct {
	Target  string
	Key     string
	Pending []engine.Migration
	Nearest []Plan
}

PlanRequired is returned when a target demands a stored plan and none matches the migration set.

func (*PlanRequired) Error

func (e *PlanRequired) Error() string

Error renders the report with the nearest stored plans next to this set.

func (*PlanRequired) FilesDiff

func (e *PlanRequired) FilesDiff() string

FilesDiff renders this set against each nearest plan, one line per plan.

type PlanStale

type PlanStale struct {
	Plan   Plan
	Reason string
	Diff   PlanDiff
	Hint   string
}

PlanStale is returned when a stored plan no longer matches the target it was taken against.

func (*PlanStale) Error

func (e *PlanStale) Error() string

Error renders the report shown on the pull request and in the CLI.

type PlanStatement

type PlanStatement struct {
	SQL     string       `json:"sql"`
	NoTx    bool         `json:"no_tx,omitempty"`
	Phase   string       `json:"phase,omitempty"`
	Batch   *PlanBatch   `json:"batch,omitempty"`
	Assert  *PlanAssert  `json:"assert,omitempty"`
	Hazards []PlanHazard `json:"hazards,omitempty"`
}

PlanStatement is one classified statement of a stored plan.

func PlanStatements

func PlanStatements(sts []engine.Statement) []PlanStatement

PlanStatements keeps the SQL, transaction mode and hazards of classified statements.

type Pool

type Pool interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Begin(ctx context.Context) (pgx.Tx, error)
}

Pool is the connection-pool surface the store needs; *pgxpool.Pool and pgx.Tx satisfy it.

type Provenance

type Provenance struct {
	CreatedBy string
	Source    string
}

Provenance records who created a run and where its files came from.

type Reconciler

type Reconciler struct {
	// contains filtered or unexported fields
}

Reconciler repairs the control plane's ledger from a target's own journal. It never writes to the target.

func NewReconciler

func NewReconciler(sched *Scheduler) *Reconciler

NewReconciler shares the scheduler's store, credential providers and engine.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, runID, target string, migs []engine.Migration, p Provenance) (Divergence, error)

Reconcile adopts into run runID every migration target's journal records that the ledger does not, taking each body from migs.

type Recorder

type Recorder func(ctx context.Context, res engine.Result) error

Recorder sees the outcome of every plan as it completes, so the ledger survives a failure mid-run.

type RetiredColumn

type RetiredColumn struct {
	Schema  string `json:"schema"`
	Table   string `json:"table"`
	Column  string `json:"column"`
	Retires string `json:"retires"`
}

RetiredColumn is a column a change-type left behind as the rollback of a completed swap.

func Unretired

func Unretired(exps map[string]Expansion) []RetiredColumn

Unretired lists every column the expansions of one run remove, so a retired one stops being reported as a rollback the target holds.

func (RetiredColumn) String

func (c RetiredColumn) String() string

String renders the retired column as a qualified reference.

type RevertPlan

type RevertPlan struct {
	Run     Run
	Applied []RunMigration
	Plans   []engine.Plan
	Newer   bool
}

RevertPlan is the down side of what a run actually applied, newest first.

func (RevertPlan) Drops

func (r RevertPlan) Drops() map[string][]engine.Drop

Drops lists every table and column the plan would remove, keyed by migration.

type RolloutPolicy

type RolloutPolicy interface {
	Split(plans []engine.Plan) (expand, contract []engine.Plan)
}

RolloutPolicy splits a run's plans into the expand and contract phases.

type Run

type Run struct {
	ID         string
	Seq        int64
	Target     string
	State      string
	Error      string
	Attempts   int
	Rollout    string
	Phase      string
	Reverts    string
	Kind       string
	Timeouts   Timeouts
	Provenance Provenance
	PlanID     string
	Retries    int
	NotBefore  *time.Time
	CreatedAt  time.Time
	FinishedAt *time.Time
	Progress   *RunProgress
	Expansions map[string]Expansion
}

Run is one migration run tracked by the control plane.

type RunMigration

type RunMigration struct {
	Migration  string
	AppliedAt  time.Time
	RevertedBy string
	Held       bool
	Adopted    bool
	Expansion  *Expansion
}

RunMigration is one migration a run put into its target's history, with the inverse frozen for it.

type RunProgress

type RunProgress struct {
	Migration string `json:"migration"`
	Statement int    `json:"statement"`
	Phase     string `json:"phase,omitempty"`
	RowsDone  int64  `json:"rows_done,omitempty"`
	RowsTotal int64  `json:"rows_total,omitempty"`
	Batches   int    `json:"batches,omitempty"`
}

RunProgress is the newest statement a running run reported, so a long backfill is visible while it runs.

type Scheduler

type Scheduler struct {
	Metrics  *metrics.Metrics
	Notifier notify.Notifier
	// contains filtered or unexported fields
}

Scheduler claims runnable runs and executes them under a heartbeated lease.

func NewScheduler

func NewScheduler(store *Store, providers map[string]creds.Provider, eng Engine, policies map[string]RolloutPolicy, cfg Config, log *slog.Logger) *Scheduler

NewScheduler wires a Scheduler.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context)

Run polls for work until ctx is done or Stop is called, then waits for the runs it started.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop tells Run to claim nothing more; the runs it already started keep their leases and end with the context Run was given.

func (*Scheduler) Tick

func (s *Scheduler) Tick(ctx context.Context)

Tick claims and executes at most one run.

type SchemaDiff

type SchemaDiff struct {
	Observed          Observation
	UpSQL             string
	DownSQL           string
	Drift             []string
	Retained          []string
	RepeatableObjects []string
}

SchemaDiff is the migration from a target's live schema to a desired one, and back.

type Scratch

type Scratch struct {
	// contains filtered or unexported fields
}

Scratch creates and drops the throwaway databases validation and diff run submitted SQL on.

func NewScratch

func NewScratch(pool *pgxpool.Pool, template string) *Scratch

NewScratch wires scratch databases onto pool; an empty template means DefaultScratchTemplate.

func (*Scratch) Check

func (s *Scratch) Check(ctx context.Context, storeDB string) ([]ScratchFinding, error)

Check reports what the scratch role may do besides making and dropping its own databases; storeDB names the control-plane database.

type ScratchFinding

type ScratchFinding struct {
	Fatal  bool
	Detail string
}

ScratchFinding is one way the scratch role reaches past the databases it makes for itself.

type Snapshot

type Snapshot struct {
	Target      string
	Fingerprint string
	Definition  string
	RunID       string
	TakenAt     time.Time
}

Snapshot is the expected schema state recorded for a target.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store persists targets, runs, files and leases in the control-plane database.

func NewStore

func NewStore(pool Pool) *Store

NewStore wraps a connection pool.

func (*Store) AdoptApplied

func (s *Store) AdoptApplied(ctx context.Context, runID, migration string) (bool, error)

AdoptApplied records a migration the run found the target already holding, and reports whether it wrote a row.

func (*Store) Applied

func (s *Store) Applied(ctx context.Context, target string) (AppliedSet, error)

Applied returns what a target's runs applied and no revert undid, whether or not the run that applied it went on to succeed.

func (*Store) AppliedMigrations

func (s *Store) AppliedMigrations(ctx context.Context, runID string) ([]RunMigration, error)

AppliedMigrations lists a run's ledger in the order the run applied it.

func (*Store) Audit

func (s *Store) Audit(ctx context.Context, e AuditEntry) error

Audit appends an entry; at and id are assigned by the store.

func (*Store) AwaitingContract

func (s *Store) AwaitingContract(ctx context.Context, target string) (Run, bool, error)

AwaitingContract returns the target's run stopped between its phases, if it has one.

func (*Store) BindPlan

func (s *Store) BindPlan(ctx context.Context, id, runID string) error

BindPlan marks a ready plan as applied by a run.

func (*Store) BoundPlan

func (s *Store) BoundPlan(ctx context.Context, target, rollout, filesHash string) (Plan, error)

BoundPlan returns the newest bound plan on a target whose rollout and submitted files match.

func (*Store) CarriedBy

func (s *Store) CarriedBy(ctx context.Context, target, migration string) (LedgerEntry, error)

CarriedBy returns the run that applied the migration on the target, or the newest that carried its file when none did.

func (*Store) Checkpoints

func (s *Store) Checkpoints(ctx context.Context, target string) ([]engine.Migration, error)

Checkpoints reads the checkpoints a target's standing ledger holds, newest first.

func (*Store) Claim

func (s *Store) Claim(ctx context.Context, holder string, ttl time.Duration) (Run, bool, error)

Claim leases the next queued run, or a running one whose lease expired; one lease per target.

func (*Store) ClaimGitHubReports

func (s *Store) ClaimGitHubReports(ctx context.Context, lease time.Duration, limit int) ([]GitHubRun, error)

ClaimGitHubReports takes the bindings whose run reached a state nobody reported yet and holds them for lease; an unmarked claim is taken again.

func (*Store) Confirm

func (s *Store) Confirm(ctx context.Context, id string) (Run, error)

Confirm requeues an awaiting_contract run for its contract phase and returns it.

func (*Store) CreateAdoption

func (s *Store) CreateAdoption(ctx context.Context, id, target, kind string, migs []engine.Migration, p Provenance) error

CreateAdoption records an already-succeeded run of kind carrying migs' files and one adopted ledger row per migration.

func (*Store) CreateRevert

func (s *Store) CreateRevert(ctx context.Context, id string, orig Run, force bool, t Timeouts, p Provenance) error

CreateRevert queues a run that undoes what another run applied; force allows a run that is not the newest un-reverted one on its target.

func (*Store) CreateRun

func (s *Store) CreateRun(ctx context.Context, id, target, rollout string, files map[string]string, t Timeouts, p Provenance, planID string, exps map[string]Expansion) error

CreateRun queues a run with its migration files, timeout overrides, provenance, bound plan and the expansions it applies in place of the file bodies.

func (*Store) Finish

func (s *Store) Finish(ctx context.Context, id, state, errText string) error

Finish records a terminal state and releases the lease by run id rather than by holder, because an operator parking a run holds none.

func (*Store) FleetMigrations

func (s *Store) FleetMigrations(ctx context.Context, f FleetFilter) (Fleet, error)

FleetMigrations reports which targets hold each migration; it reads the ledger only, so it answers while a target is unreachable.

func (*Store) GetTS

func (s *Store) GetTS(ctx context.Context, kind, key string) (string, string, error)

GetTS implements notify.TSStore; a missing key yields empty strings.

func (*Store) GitHubBindings

func (s *Store) GitHubBindings(ctx context.Context) (map[string]string, error)

GitHubBindings returns the stored repository binding of every target that carries one, by target name.

func (*Store) GitHubRunsOf

func (s *Store) GitHubRunsOf(ctx context.Context, repository string, pull int, target string) ([]GitHubRun, error)

GitHubRunsOf lists the runs one pull request created on one target, newest first, with their live state.

func (*Store) Heartbeat

func (s *Store) Heartbeat(ctx context.Context, runID, holder string, ttl time.Duration) error

Heartbeat extends the holder's lease; ErrLeaseLost means another holder took it, and holder is matched whole.

func (*Store) History

func (s *Store) History(ctx context.Context, target string) ([]HistoryRun, error)

History returns what every run of a target applied and no revert undid, oldest first; a held migration is in neither this nor Applied.

func (*Store) LastRun

func (s *Store) LastRun(ctx context.Context, target string) (r Run, ok bool, err error)

LastRun returns the most recently created run for target; ok is false when it never had one.

func (*Store) ListAudit

func (s *Store) ListAudit(ctx context.Context, target, runID string, limit int) ([]AuditEntry, error)

ListAudit returns the newest entries first, optionally filtered by target and run; limit caps the page (100 when zero, MaxPageSize at most).

func (*Store) ListCredentialStores

func (s *Store) ListCredentialStores(ctx context.Context) ([]CredentialStore, error)

ListCredentialStores returns every registered store by name.

func (*Store) ListDriftEvents

func (s *Store) ListDriftEvents(ctx context.Context, target string) ([]DriftEvent, error)

ListDriftEvents returns recent drift events, optionally filtered by target.

func (*Store) ListPlans

func (s *Store) ListPlans(ctx context.Context, target string, limit int) ([]Plan, error)

ListPlans returns a target's plans, newest first; limit caps the page (100 when zero, MaxPageSize at most).

func (*Store) ListRuns

func (s *Store) ListRuns(ctx context.Context, target string) ([]Run, error)

ListRuns returns recent runs, optionally filtered by target.

func (*Store) ListTargets

func (s *Store) ListTargets(ctx context.Context, since time.Time) ([]TargetSummary, error)

ListTargets summarises every target by name, counting ready plans created at or after since.

func (*Store) LockTarget

func (s *Store) LockTarget(ctx context.Context, name string) (string, map[string]string, error)

LockTarget is Target for update, answering an unregistered name with an empty provider and config.

func (*Store) MarkGitHubReported

func (s *Store) MarkGitHubReported(ctx context.Context, runID, state string) error

MarkGitHubReported records the state the pull request was told about and releases the claim.

func (*Store) MarkReverted

func (s *Store) MarkReverted(ctx context.Context, origID, revertID, migration string) error

MarkReverted records that revertID undid one migration of run origID.

func (*Store) Newer

func (s *Store) Newer(ctx context.Context, orig Run) (bool, error)

Newer reports whether a run created after orig still stands on its target.

func (*Store) OpenDrift

func (s *Store) OpenDrift(ctx context.Context, target string) (bool, error)

OpenDrift reports whether target has a drift event nobody has resolved or re-baselined.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping reports whether the store answers a trivial query.

func (*Store) Plan

func (s *Store) Plan(ctx context.Context, id string) (Plan, error)

Plan returns one plan by id.

func (*Store) PlanFiles

func (s *Store) PlanFiles(ctx context.Context, id string) (map[string]string, error)

PlanFiles returns the migration files stored with a plan.

func (*Store) PlanRevert

func (s *Store) PlanRevert(ctx context.Context, id string) (RevertPlan, error)

PlanRevert builds the plans that undo run id: the down side of every migration its ledger still holds, in reverse order of application.

func (*Store) PutTS

func (s *Store) PutTS(ctx context.Context, kind, key, channel, ts string) error

PutTS implements notify.TSStore.

func (*Store) ReadyPlan

func (s *Store) ReadyPlan(ctx context.Context, target, key string, since time.Time) (Plan, error)

ReadyPlan returns the ready plan for a key on a target, created at or after since.

func (*Store) ReadyPlanCount

func (s *Store) ReadyPlanCount(ctx context.Context, target string, since time.Time) (int, error)

ReadyPlanCount counts a target's ready plans created at or after since.

func (*Store) RecordApplied

func (s *Store) RecordApplied(ctx context.Context, runID, migration string, held bool, exp *Expansion) error

RecordApplied adds a migration to a run's ledger, or updates it when the contract phase completes it.

func (*Store) RecordDelivery

func (s *Store) RecordDelivery(ctx context.Context, id, event, repository string) (bool, error)

RecordDelivery records a webhook delivery id and reports whether it is the first sight of it.

func (*Store) RecordDrift

func (s *Store) RecordDrift(ctx context.Context, target, baseline, diff string) (bool, error)

RecordDrift opens a drift event while baseline is still the target's fingerprint and no identical one is open; reports whether it did.

func (*Store) RecordGitHubRun

func (s *Store) RecordGitHubRun(ctx context.Context, g GitHubRun) error

RecordGitHubRun binds run to a pull request; a second command over the same run replaces the binding.

func (*Store) RegisterCredentialStore

func (s *Store) RegisterCredentialStore(ctx context.Context, cs CredentialStore) error

RegisterCredentialStore upserts a credential store; a target already pointed at it moves with it.

func (*Store) RegisterTarget

func (s *Store) RegisterTarget(ctx context.Context, name, provider string, config map[string]string) error

RegisterTarget upserts a target, replacing whatever config the row held; the credential store is a column, so a foreign key refuses a dangling one.

func (*Store) ResolveDrift

func (s *Store) ResolveDrift(ctx context.Context, target string) (bool, error)

ResolveDrift closes every open drift event for a target and reports whether any was open.

func (*Store) Resume

func (s *Store) Resume(ctx context.Context, id string) (Run, error)

Resume requeues a failed or parked run and returns it.

func (*Store) RetireColumns

func (s *Store) RetireColumns(ctx context.Context, target, runID, migration string, cols []RetiredColumn) error

RetireColumns records the columns a run left behind so a desired-schema diff stops proposing their drop.

func (*Store) RetirePlan

func (s *Store) RetirePlan(ctx context.Context, id string) error

RetirePlan marks a bound plan superseded so a later job with the same files plans afresh.

func (*Store) RetiredColumns

func (s *Store) RetiredColumns(ctx context.Context, target string) ([]RetiredColumn, error)

RetiredColumns lists the columns a target keeps only as the rollback of a completed change-type.

func (*Store) Retry

func (s *Store) Retry(ctx context.Context, id, errText string, wait time.Duration) error

Retry requeues a running run after a transient failure, holding it back for wait and releasing its lease.

func (*Store) RevertTarget

func (s *Store) RevertTarget(ctx context.Context, target string) (Run, error)

RevertTarget returns the newest un-reverted run on target, which is what a revert with no run id acts on.

func (*Store) Run

func (s *Store) Run(ctx context.Context, id string) (Run, error)

Run returns one run by id.

func (*Store) RunFiles

func (s *Store) RunFiles(ctx context.Context, id string) (map[string]string, error)

RunFiles returns the migration files attached to a run.

func (*Store) RunStats

func (s *Store) RunStats(ctx context.Context) ([]metrics.RunStat, error)

RunStats counts runs per target and state with the age of the oldest one.

func (*Store) RunsApplying

func (s *Store) RunsApplying(ctx context.Context, target string, since time.Time) (map[string]string, error)

RunsApplying maps each migration held by a succeeded run of target created after since to that run's id.

func (*Store) SavePlan

func (s *Store) SavePlan(ctx context.Context, p Plan, files map[string]string) error

SavePlan stores a ready plan with its files; a ready plan with the same key on the target is replaced.

func (*Store) SaveProgress

func (s *Store) SaveProgress(ctx context.Context, id string, p RunProgress) error

SaveProgress records what the newest statement of a running run reported; every transition that starts or ends an attempt clears it.

func (*Store) SaveSnapshot

func (s *Store) SaveSnapshot(ctx context.Context, target, fingerprint, definition, runID string) error

SaveSnapshot upserts the expected schema for a target and resolves open drift.

func (*Store) SelectVersion

func (s *Store) SelectVersion(ctx context.Context, target string, plans []engine.Plan, to int64) (keep, withheld []engine.Plan, err error)

SelectVersion splits a submitted set at a version target: what is at or below to is kept, the rest withheld.

func (*Store) SnapshotFor

func (s *Store) SnapshotFor(ctx context.Context, target string) (Snapshot, error)

SnapshotFor returns the expected schema recorded for a target.

func (*Store) SnapshotTargets

func (s *Store) SnapshotTargets(ctx context.Context) ([]string, error)

SnapshotTargets lists targets that have an expected schema recorded.

func (*Store) SupersedePlan

func (s *Store) SupersedePlan(ctx context.Context, id string, next Plan, files map[string]string) error

SupersedePlan retires a ready plan and stores next in its place, linking the two.

func (*Store) SweepDeliveries

func (s *Store) SweepDeliveries(ctx context.Context, before time.Time) (int64, error)

SweepDeliveries deletes recorded delivery ids received before t and reports how many went.

func (*Store) SweepGitHubRuns

func (s *Store) SweepGitHubRuns(ctx context.Context, before time.Time) (int64, error)

SweepGitHubRuns deletes reported bindings created before t and reports how many went.

func (*Store) SweepPlans

func (s *Store) SweepPlans(ctx context.Context, olderThan time.Time) (int64, error)

SweepPlans deletes bound and superseded plans created before olderThan, keeping those an unfinished run still applies.

func (*Store) Target

func (s *Store) Target(ctx context.Context, name string) (string, map[string]string, error)

Target returns a target's provider name and config.

func (*Store) Transact

func (s *Store) Transact(ctx context.Context, fn func(tx *Store) error) error

Transact runs fn on a store bound to one transaction; its writes stay invisible to other sessions until fn returns nil.

func (*Store) UnretireColumns

func (s *Store) UnretireColumns(ctx context.Context, target string, cols []RetiredColumn) error

UnretireColumns forgets columns a revert renamed back into place.

func (*Store) VaultStore

func (s *Store) VaultStore(ctx context.Context, name string) (creds.VaultStore, error)

VaultStore answers where a named credential store points; it is the vault provider's lookup.

type TargetRegistration

type TargetRegistration struct {
	Name                string
	Provider            string
	CredentialStore     string
	VaultPath           string
	VaultTemplate       string
	SecretPath          string
	DSNRegistered       bool
	Timeouts            Timeouts
	SearchPath          string
	RequirePlan         bool
	KeepOld             bool
	IgnoreAdoptedTables bool
	GitHubRepositories  []string
}

TargetRegistration is a target as it was registered, and carries no credential.

func RegistrationOf

func RegistrationOf(name, provider string, config map[string]string) TargetRegistration

RegistrationOf reads a stored target config back into the settings it was registered with.

func (TargetRegistration) Fields

func (r TargetRegistration) Fields() []any

Fields is the registration as ordered log attributes, and the only rendering of one.

type TargetStatus

type TargetStatus struct {
	Target      string
	Provider    string
	Timeouts    Timeouts
	SearchPath  string
	Applied     []engine.Applied
	Repeatables []engine.Repeatable
	LastRun     *Run
	Snapshot    *Snapshot
	OpenDrift   bool
	Unreachable string
}

TargetStatus is what the control plane knows about a target next to what its database reports.

type TargetSummary

type TargetSummary struct {
	TargetRegistration
	LastRun         *Run
	AttentionRuns   int
	UnresolvedDrift bool
	ReadyPlans      int
	AppliedCount    int
}

TargetSummary is the control plane's own view of a registered target, assembled without connecting to it.

type Timeouts

type Timeouts struct {
	Lock      string
	Statement string
}

Timeouts are per-statement timeouts as Go duration strings; empty means inherit.

func (Timeouts) Options

func (t Timeouts) Options() (engine.Options, error)

Options parses and validates the timeouts; the lock timeout must be positive, the statement timeout may be 0.

func (Timeouts) Over

func (t Timeouts) Over(base Timeouts) Timeouts

Over returns t with every empty field taken from base.

type Validation

type Validation struct {
	Base         string
	Effects      [][]string
	Fingerprints []string
	Changes      [][]engine.ObjectChange
	Expansions   map[string]Expansion
	Plans        []engine.Plan
	Replayed     int
	Collapsed    int
}

Validation is what the scratch database looked like after the history and after each plan in turn.

type Validator

type Validator struct {
	Expander *Expander
	// contains filtered or unexported fields
}

Validator replays a target's history on a scratch database and applies new plans on top.

func NewValidator

func NewValidator(scratch *Scratch, store *Store, newID func() string) *Validator

NewValidator wires a Validator over the scratch connection.

func (*Validator) Replay

func (v *Validator) Replay(ctx context.Context, conn engine.DB, target, searchPath string, plans []engine.Plan) error

Replay rebuilds target's recorded history on conn and applies plans on top; a migration the history already covers keeps its own expansion.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, target string, plans []engine.Plan, searchPath string) (Validation, error)

Validate replays the history, applies each plan on top and snapshots the schema after every step.

Jump to

Keyboard shortcuts

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