Documentation ¶
Overview ¶
Package applier handles execution of generating diffs between schemas, and appropriate application of the generated DDL.
Index ¶
- func DebugLogUnsupportedDiff(err *tengo.UnsupportedDiffError)
- func StatementModifiersForDir(dir *fs.Dir) (mods tengo.StatementModifiers, err error)
- func TargetGroupChanForDir(dir *fs.Dir) (<-chan TargetGroup, int)
- func VerifyDiff(diff *tengo.SchemaDiff, t *Target) error
- func Worker(ctx context.Context, targetGroups <-chan TargetGroup, results chan<- Result, ...) error
- type ConfigError
- type DDLStatement
- type Printer
- type Result
- type Target
- type TargetGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugLogUnsupportedDiff ¶
func DebugLogUnsupportedDiff(err *tengo.UnsupportedDiffError)
DebugLogUnsupportedDiff logs (at Debug level) the reason why an object is unsupported for diff/alter operations.
func StatementModifiersForDir ¶
func StatementModifiersForDir(dir *fs.Dir) (mods tengo.StatementModifiers, err error)
StatementModifiersForDir returns a set of DDL modifiers, based on the directory's configuration.
func TargetGroupChanForDir ¶
func TargetGroupChanForDir(dir *fs.Dir) (<-chan TargetGroup, int)
TargetGroupChanForDir returns a channel for obtaining TargetGroups for this dir and its subdirs, and count of directories that were skipped due to non- fatal errors.
func VerifyDiff ¶
func VerifyDiff(diff *tengo.SchemaDiff, t *Target) error
VerifyDiff verifies the result of all AlterTable values found in diff.TableDiffs, confirming that applying the corresponding ALTER would bring a table from the version in t.SchemaFromInstance to the version in t.SchemaFromDir.
func Worker ¶
func Worker(ctx context.Context, targetGroups <-chan TargetGroup, results chan<- Result, printer *Printer) error
Worker reads TargetGroups from the input channel and performs the appropriate diff/push operation on each target per TargetGroup. When there are no more TargetGroups to read, it writes its aggregate Result to the output channel. If a fatal error occurs, it will be returned immediately; Worker is meant to be called via an errgroup (see golang.org/x/sync/errgroup).
Types ¶
type ConfigError ¶
type ConfigError string
ConfigError represents a configuration problem encountered at runtime.
func (ConfigError) Error ¶
func (ce ConfigError) Error() string
Error satisfies the builtin error interface.
type DDLStatement ¶
type DDLStatement struct {
// contains filtered or unexported fields
}
DDLStatement represents a DDL SQL statement (CREATE TABLE, ALTER TABLE, etc). It may represent an external command to shell out to, or a DDL statement to run directly against a DB.
func NewDDLStatement ¶
func NewDDLStatement(diff tengo.ObjectDiff, mods tengo.StatementModifiers, target *Target) (ddl *DDLStatement, err error)
NewDDLStatement creates and returns a DDLStatement. If the statement ends up being a no-op due to mods, both returned values will be nil. In the case of an error constructing the statement (mods disallowing destructive DDL, invalid variable interpolation in --alter-wrapper, etc), the DDLStatement pointer will be nil, and a non-nil error will be returned.
func (*DDLStatement) Execute ¶
func (ddl *DDLStatement) Execute() error
Execute runs the DDL statement, either by running a SQL query against a DB, or shelling out to an external program, as appropriate.
func (*DDLStatement) IsShellOut ¶
func (ddl *DDLStatement) IsShellOut() bool
IsShellOut returns true if the DDL is to be executed via shelling out to an external binary, or false if the DDL represents SQL to be executed directly via a standard database connection.
func (*DDLStatement) String ¶
func (ddl *DDLStatement) String() string
String returns a string representation of ddl. If an external command is in use, the returned string will be prefixed with "\!", the MySQL CLI command shortcut for "system" shellout.
type Printer ¶
Printer is capable of sending output to STDOUT in a readable manner despite being called from multiple pushworker goroutines.
func NewPrinter ¶
NewPrinter returns a pointer to a new Printer. If briefMode is true, this printer is used to print instance names ("host:port\n") of instances that have one or more differences found. If briefMode is false, this printer is used to print any arbitrary output specific to an instance and schema.
type Result ¶
Result stores the overall result of all operations the worker has completed.
func SumResults ¶
SumResults adds up the supplied results to return a single combined result.
type Target ¶
type Target struct { Instance *tengo.Instance Dir *fs.Dir SchemaFromInstance *tengo.Schema SchemaFromDir *tengo.Schema }
Target represents a unit of operation. For each dir that defines at least one instance and schema, targets are generated as the cartesian product of (instances this dir maps to) x (schemas that this dir maps to on each instance).
func TargetsForDir ¶
TargetsForDir examines dir's configuration, figures out what Target(s) the dir maps to, and then recursively descends through dir's subdirectories to do the same.
If firstOnly is true, any directory that normally maps to multiple instances and/or schemas will only use of the first of each.
Targets are returned as a slice with no guaranteed ordering. Errors are not fatal; a count of skipped dirs is returned instead.
type TargetGroup ¶
type TargetGroup []*Target
TargetGroup represents a group of Targets that all have the same Instance.