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
- func BaseChanges(name string) changeset.Dialect
- func BlankPartial(data []byte, tables []PartialTable) []byte
- func DescribeDestructive(c schema.Change) (bool, string)
- func Exclude(s *schema.Schema, patterns []string) error
- func MapCapabilities(probed capabilities.BackendCapabilities) (engine.Capabilities, error)
- func Mentions(definition, name string) bool
- func NameString(n migrate.Name) string
- func ObjectOf(o schema.Object) (string, migrate.Name, bool)
- func PartialNames(tables []PartialTable) map[string]bool
- func QuoteIdent(s string) string
- func SplitPartial(file, source string) (string, map[string]bool, error)
- func WithExclude(ctx context.Context, patterns []string) context.Context
- func WithPartial(s migrate.Schema, names map[string]bool) migrate.Schema
- type Atlas
- type Backend
- type Dialect
- func (d *Dialect) Capabilities(ctx context.Context, q engine.Querier) (engine.Capabilities, error)
- func (d *Dialect) Dependents(ctx context.Context, q engine.Querier, current migrate.Schema, ...) ([]engine.Dependent, error)
- func (d *Dialect) Diff(current, desired migrate.Schema) (engine.Diff, error)
- func (d *Dialect) Exec(ctx context.Context, q engine.Querier, s engine.Statement) error
- func (d *Dialect) Inspect(ctx context.Context, q engine.Querier, scope engine.Scope) (engine.Inspection, error)
- func (d *Dialect) Name() string
- func (d *Dialect) Open(ctx context.Context, conn *sql.Conn, opts engine.SessionOptions) (engine.UnitSession, error)
- func (d *Dialect) Preconditions(change migrate.Change, current, desired migrate.Schema, _ engine.Capabilities) ([]engine.Precondition, error)
- func (d *Dialect) Reconcile(ctx context.Context, q engine.Querier, current, desired migrate.Schema) (migrate.Schema, error)
- func (d *Dialect) SameDependent(before, after engine.Dependent) (bool, error)
- func (d *Dialect) SchemaFromAtlas(s *schema.Schema) (migrate.Schema, error)
- func (d *Dialect) SchemaFromHCL(hcl string) (migrate.Schema, error)
- type Extras
- type PartialTable
Constants ¶
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 ¶
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 ¶
DescribeDestructive is the destructive rule shared by every Atlas dialect.
func Exclude ¶
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 NameString ¶
NameString renders a schema-qualified, quoted object name.
func PartialNames ¶
func PartialNames(tables []PartialTable) map[string]bool
PartialNames lists the tables declared `partial = true`.
func QuoteIdent ¶
QuoteIdent quotes an identifier for every Atlas dialect (double quotes).
func SplitPartial ¶
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 ¶
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.
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 (*Dialect) Capabilities ¶
Capabilities probes the backend through database/capabilities. With q == nil it answers the backend's static, offline capabilities.
func (*Dialect) Dependents ¶
func (*Dialect) Diff ¶
Diff decodes both snapshots, keeps the tables still in each projection and describes the changes between them.
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) 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 (*Dialect) SchemaFromAtlas ¶
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 ¶
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.