model

package
v0.0.0-...-2a589a5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 2 Imported by: 16

Documentation

Overview

Package model provides public data structures and interfaces to represent migration operations.

The model package contains no non-trivial implementations and has no dependencies outside of the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationOptions

type ApplicationOptions struct {
	DryRun bool `bson:"dry_run" json:"dry_run" yaml:"dry_run"`
	Limit  int  `bson:"limit" json:"limit" yaml:"limit"`
}

ApplicationOptions define aspects of the application's behavior as a whole.

type Configuration

type Configuration struct {
	Options          ApplicationOptions             `bson:"options" json:"options" yaml:"options"`
	SimpleMigrations []ConfigurationSimpleMigration `bson:"simple_migrations" json:"simple_migrations" yaml:"simple_migrations"`
	ManualMigrations []ConfigurationManualMigration `bson:"manual_migrations" json:"manual_migrations" yaml:"manual_migrations"`
	StreamMigrations []ConfigurationManualMigration `bson:"stream_migrations" json:"stream_migrations" yaml:"stream_migrations"`
}

Configuration describes migrations configured in a file passed to anser. This kind of migration are typically populated directly from a configuration file, unlike most anser migrations which are implemented and described in Go code.

type ConfigurationManualMigration

type ConfigurationManualMigration struct {
	Options GeneratorOptions  `bson:"options" json:"options" yaml:"options"`
	Name    string            `bson:"name" json:"name" yaml:"name"`
	Params  map[string]string `bson:"params,omitempty" json:"params,omitempty" yaml:"params,omitempty"`
}

ConfigurationManualMigrations defines either a stream/manual migration, as the definition for either depend on having the migration implementation for that name to be defined. The params field are only used by custom migrations.

type ConfigurationSimpleMigration

type ConfigurationSimpleMigration struct {
	Options GeneratorOptions       `bson:"options" json:"options" yaml:"options"`
	Update  map[string]interface{} `bson:"update" json:"update" yaml:"update"`
}

ConfigurationSimpleMigrations defines a migration that provides, in essence a single-document update as the migration.

type DependencyNetworker

type DependencyNetworker interface {
	// Add inserts a list of dependencies for a given item. If the
	// slice of dependencies is empty, Add is a noop. Furthermore,
	// the Add method provides no validation, and will do nothing
	// to prevent cycles or broken dependencies.
	Add(string, []string)

	// Resolve, returns all of the dependencies for the specified task.
	Resolve(string) []string

	// All returns a list of all tasks that have registered
	// dependencies.
	All() []string

	// Network returns the dependency graph for all registered
	// tasks as a mapping of task IDs to the IDs of its
	// dependencies.
	Network() map[string][]string

	// Validate returns errors if there are either dependencies
	// specified that do not have tasks available *or* if there
	// are dependency cycles.
	Validate() error

	// AddGroup and GetGroup set and return the lists of tasks
	// that belong to a specific task group. Unlike the specific
	// task dependency setters.
	AddGroup(string, []string)
	GetGroup(string) []string

	// For introspection and convince, DependencyNetworker
	// composes implementations of common interfaces.
	fmt.Stringer
	json.Marshaler
}

DependencyNetworker provides answers to questions about the dependencies of a task and is available white generating migrations. Methods should do nothing in particular

Implementations should be mutable and thread-safe.

The DependencyNetworker interface definition is in the model package because it has no external dependencies, and placing it in other packages would lead to cycles. The default implementation is in the top level package.

type GeneratorOptions

type GeneratorOptions struct {
	JobID     string                 `bson:"_id" json:"id" yaml:"id"`
	DependsOn []string               `bson:"dependencies" json:"dependencies" yaml:"dependencies"`
	NS        Namespace              `bson:"namespace" json:"namespace" yaml:"namespace"`
	Query     map[string]interface{} `bson:"query" json:"query" yaml:"query"`
	Limit     int                    `bson:"limit" json:"limit" yaml:"limit"`
}

GeneratorOptions hold all options common to all generator types, and are used in the configuration of generator functions and their dependency relationships.

func (GeneratorOptions) IsValid

func (o GeneratorOptions) IsValid() bool

type Manual

type Manual struct {
	// ID returns the _id field of the document that is the
	// input of the migration.
	ID interface{} `bson:"id" json:"id" yaml:"id"`

	// The name of the migration function to run. This function
	// must be defined in the migration registry
	OperationName string `bson:"op_name" json:"op_name" yaml:"op_name"`

	// Migration holds the ID of the migration operation,
	// typically the name of the class of migration and
	Migration string `bson:"migration_id" json:"migration_id" yaml:"migration_id"`

	// Namespace holds a struct that describes which database and
	// collection where the query for the input document should run.
	Namespace Namespace `bson:"namespace" json:"namespace" yaml:"namespace"`
}

MigrationDefinitionManual defines an operations that runs an arbitrary function given the input of an mgo.Session pointer and

type MigrationMetadata

type MigrationMetadata struct {
	ID        string `bson:"_id" json:"id" yaml:"id"`
	Migration string `bson:"migration" json:"migration" yaml:"migration"`
	HasErrors bool   `bson:"has_errors" json:"has_errors" yaml:"has_errors"`
	Completed bool   `bson:"completed" json:"completed" yaml:"completed"`
}

MigrationMetadata records data about completed migrations.

func (*MigrationMetadata) Satisfied

func (m *MigrationMetadata) Satisfied() bool

Satisfies reports if a migration has completed without errors.

type Namespace

type Namespace struct {
	DB         string `bson:"db_name" json:"db_name" yaml:"db_name"`
	Collection string `bson:"collection" json:"collection" yaml:"collection"`
}

Namespace reflects a MongoDB database name and collection pair.

func (Namespace) IsValid

func (ns Namespace) IsValid() bool

IsValid checks

func (Namespace) String

func (ns Namespace) String() string

type Simple

type Simple struct {
	// ID returns the _id field of the document that is the
	// subject of the migration.
	ID interface{} `bson:"id" json:"id" yaml:"id"`

	// Update is a specification for the update
	// operation. This is converted to a bson.M{} (but is typed as
	// a map to allow migration implementations to *not* depend upon
	// bson.M
	Update map[string]interface{} `bson:"update" json:"update" yaml:"update"`

	// Migration holds the ID of the migration operation,
	// typically the name of the class of migration and
	Migration string `bson:"migration_id" json:"migration_id" yaml:"migration_id"`

	// Namespace holds a struct that describes which database and
	// collection where the migration should run
	Namespace Namespace `bson:"namespace" json:"namespace" yaml:"namespace"`
}

MigrationDefinitionSimple defines a single-document operation, performing a single document update that operates on one collection.

type Stream

type Stream struct {
	Query map[string]interface{} `bson:"query" json:"query" yaml:"query"`

	// The name of a registered DocumentProcessor implementation.
	// Because the producer isn't versioned, changes to the
	// implementation of the Producer between migration runs, may
	// complicate idempotency requirements.
	ProcessorName string `bson:"producer" json:"producer" yaml:"producer"`

	// Migration holds the ID of the migration operation,
	// typically the name of the class of migration and
	Migration string `bson:"migration_id" json:"migration_id" yaml:"migration_id"`

	// Namespace holds a struct that describes which database and
	// collection where the query for the input document should run.
	Namespace Namespace `bson:"namespace" json:"namespace" yaml:"namespace"`
}

MigrationDefinitionStream is a migration definition form that has, that can processes a stream of documents, using an implementation of the DocumentProducer interface.

Jump to

Keyboard shortcuts

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