atlasdriver

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atlasdriver is the shared engine.Dialect implementation for the dialects that plan with an upstream Atlas driver (Postgres and SQLite). A Backend supplies what differs: the Atlas wiring, objects Atlas does not model, forced rebuilds and session handling.

Index

Constants

View Source
const DesiredHCLFile = "desired.hcl"

DesiredHCLFile names declared HCL given as text in the errors that read it.

Variables

This section is empty.

Functions

func BaseChanges

func BaseChanges(name string) changeset.Dialect

BaseChanges is the changeset dialect every Atlas dialect starts from.

func BlankPartial

func BlankPartial(data []byte, tables []PartialTable) []byte

BlankPartial returns data with the partial attributes of tables replaced by spaces, keeping every line and offset, so the upstream evaluator never sees them.

func DescribeDestructive

func DescribeDestructive(c schema.Change) (bool, string)

DescribeDestructive is the destructive rule shared by every Atlas dialect.

func Exclude

func Exclude(s *schema.Schema, patterns []string) error

Exclude removes the objects the patterns name from an evaluated schema, so a declared schema hides the same objects an inspected one does.

func MapCapabilities

func MapCapabilities(probed capabilities.BackendCapabilities) (engine.Capabilities, error)

MapCapabilities converts a probed backend description to the engine's capabilities: the fingerprint, the transactional-DDL flag and one feature per reported capability, keyed by its BackendCapability value.

func Mentions

func Mentions(definition, name string) bool

Mentions reports whether definition uses name as a whole identifier.

func NameString

func NameString(n migrate.Name) string

NameString renders a schema-qualified, quoted object name.

func ObjectOf

func ObjectOf(o schema.Object) (string, migrate.Name, bool)

ObjectOf names the schema objects other than tables a change can act on.

func PartialNames

func PartialNames(tables []PartialTable) map[string]bool

PartialNames lists the tables declared `partial = true`.

func QuoteIdent

func QuoteIdent(s string) string

QuoteIdent quotes an identifier for every Atlas dialect (double quotes).

func SplitPartial

func SplitPartial(file, source string) (string, map[string]bool, error)

SplitPartial reads the partial declarations of one HCL document (an error names the file, line and table of a value that is not a boolean) and returns the document without them, and the names of the tables declared partial.

func WithExclude

func WithExclude(ctx context.Context, patterns []string) context.Context

WithExclude returns a context under which Inspect hides the objects the Atlas glob patterns name ("table", "table.column", "table.*"), exactly as Atlas's own inspection exclusions do. engine.Scope has no place for them, and the same context must reach every Inspect of one plan and its apply, so the postcondition of a unit sees the same schema the plan did.

func WithPartial

func WithPartial(s migrate.Schema, names map[string]bool) migrate.Schema

WithPartial marks the named tables of s partial. A name s does not hold was left out of the schema on purpose (an exclusion), so it is skipped.

Types

type Atlas

type Atlas struct {
	Marshal schemahcl.Marshaler
	Eval    schemahcl.Evaluator
	Differ  schema.Differ
	Planner atlas.PlanApplier
	// Open builds an inspecting driver over a live connection.
	Open       func(schema.ExecQuerier) (atlas.Driver, error)
	FormatType func(schema.Type) (string, error)
	// IndexFilter reads a partial index predicate from index attributes.
	IndexFilter func([]schema.Attr) string
}

Atlas is a dialect's Atlas wiring. The differ and planner are the offline ones, because engine.Dialect.Diff has no database handle.

type Backend

type Backend interface {
	// Name is the registered dialect name and the capability probe's backend.
	Name() string
	// OfflineCapabilities are the capabilities every server of the dialect has
	// (see engine.Dialect.Capabilities with q == nil): no fingerprint, and only
	// the features no version can lack.
	OfflineCapabilities() engine.Capabilities
	Atlas() Atlas
	Changes() changeset.Dialect
	// ValidateSchema rejects a schema name the dialect cannot migrate.
	ValidateSchema(name string) error
	// Extras reads views, triggers and the other objects Atlas does not model.
	Extras(ctx context.Context, q engine.Querier, schemaName string) (Extras, error)
	// Forcing lists the changes whose columns force dependents to be rebuilt.
	Forcing(set *changeset.Set, changes []schema.Change) ([]engine.Forcing, error)
	// Dependents lists what depends on columns; q == nil derives from current only.
	Dependents(ctx context.Context, q engine.Querier, current migrate.Schema, columns []engine.ColumnRef) ([]engine.Dependent, error)
	// Open starts a unit on its dedicated connection (see engine.Dialect.Open).
	Open(ctx context.Context, conn *sql.Conn, opts engine.SessionOptions) (engine.UnitSession, error)
	// Reconcile rewrites des in place so that attributes the database considers
	// equal to the live ones in cur are spelled like them, for the tables keep
	// accepts, and reports whether it changed anything. It must be idempotent.
	Reconcile(ctx context.Context, q engine.Querier, cur, des *schema.Schema, keep func(table string) bool) (bool, error)
	// SameDependent reports whether a rebuilt dependent is back as it was.
	SameDependent(before, after engine.Dependent) (bool, error)
	Exec(ctx context.Context, q engine.Querier, s engine.Statement) error
}

Backend is the part of a dialect that the shared implementation cannot derive.

type Dialect

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

Dialect implements engine.Dialect over a Backend.

func New

func New(b Backend) *Dialect

New wraps a backend. The caller registers the result with engine.Register.

func (*Dialect) Capabilities

func (d *Dialect) Capabilities(ctx context.Context, q engine.Querier) (engine.Capabilities, error)

Capabilities probes the backend through database/capabilities. With q == nil it answers the backend's static, offline capabilities.

func (*Dialect) Dependents

func (d *Dialect) Dependents(ctx context.Context, q engine.Querier, current migrate.Schema, columns []engine.ColumnRef) ([]engine.Dependent, error)

func (*Dialect) Diff

func (d *Dialect) Diff(current, desired migrate.Schema) (engine.Diff, error)

Diff decodes both snapshots, keeps the tables still in each projection and describes the changes between them.

func (*Dialect) Exec

func (*Dialect) Inspect

func (d *Dialect) Inspect(ctx context.Context, q engine.Querier, scope engine.Scope) (engine.Inspection, error)

Inspect reads one schema. Declared scope returns exactly the scope's objects that exist; complete scope returns the whole schema. Objects that cannot be managed faithfully come back as per-object refusals, never as a failure of the schema, so an untouched one never blocks a plan.

func (*Dialect) Name

func (d *Dialect) Name() string

func (*Dialect) Open

func (d *Dialect) Open(ctx context.Context, conn *sql.Conn, opts engine.SessionOptions) (engine.UnitSession, error)

func (*Dialect) Preconditions

func (d *Dialect) Preconditions(change migrate.Change, current, desired migrate.Schema, _ engine.Capabilities) ([]engine.Precondition, error)

Preconditions guards the changes that fail on existing data: a column made NOT NULL (any NULL) and a unique index or primary key added to an existing table (any duplicate). Each is a query that must return no rows.

func (*Dialect) Reconcile

func (d *Dialect) Reconcile(ctx context.Context, q engine.Querier, current, desired migrate.Schema) (migrate.Schema, error)

Reconcile spells the desired schema's attributes like the live ones where the database considers them equal (the backend decides which attributes, and how it asks). Native and the projection are rewritten together; a schema nothing changes in is returned as it is, so a second call is a no-op.

func (*Dialect) SameDependent

func (d *Dialect) SameDependent(before, after engine.Dependent) (bool, error)

func (*Dialect) SchemaFromAtlas

func (d *Dialect) SchemaFromAtlas(s *schema.Schema) (migrate.Schema, error)

SchemaFromAtlas is SchemaFromHCL for a schema the caller already evaluated (with variables, remapped or projected to the dialect). It refuses what the engine does not manage instead of dropping it from the snapshot.

func (*Dialect) SchemaFromHCL

func (d *Dialect) SchemaFromHCL(hcl string) (migrate.Schema, error)

SchemaFromHCL turns declared Atlas HCL into the schema the engine plans toward: canonical Native plus the projection of every table and enum type. A table's `partial = true` is read from the HCL before the Atlas evaluator sees it and kept on the projection (see partialAttr).

type Extras

type Extras struct {
	// Refusals name objects (or tables carrying a feature) that cannot be managed faithfully.
	Refusals []engine.Refusal
	// Definitions are objects carried as definitions only (views), so they can be rebuilt as dependents.
	Definitions []migrate.Definition
}

Extras are the objects of a schema that Atlas does not model.

type PartialTable

type PartialTable struct {
	// Name is the block's name (its last label).
	Name    string
	Partial bool
	// Range is the attribute's source, so evaluation can be given the file without it.
	Range hcl.Range
}

PartialTable is the `partial` attribute of one table block.

func ReadPartial

func ReadPartial(file string, body *hclsyntax.Body, ctx *hcl.EvalContext) ([]PartialTable, error)

ReadPartial reads the `partial` attribute of every table block of one parsed file. ctx evaluates variables the value may use; nil allows literals only. A value that is not true or false is an error naming the file, line and table.

Jump to

Keyboard shortcuts

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