Documentation
¶
Overview ¶
Package core provides the main migration functionality for gomiger
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseMigrator ¶
type BaseMigrator struct {
BaseMigratorAbstractMethods
Migrations []Migration
}
BaseMigrator is the base migrator for controlling flow. It does not connect or execute to any database.
type BaseMigratorAbstractMethods ¶
type BaseMigratorAbstractMethods interface {
Connect(ctx context.Context) error
GetSchema(ctx context.Context, version string) (*Schema, error)
ApplyMigration(ctx context.Context, mi Migration) error
RevertMigration(ctx context.Context, mi Migration) error
}
BaseMigratorAbstractMethods defines the methods that must be implemented by a concrete migrator.
type Gomiger ¶
type Gomiger interface {
Up(ctx context.Context, toVersion string) error
Down(ctx context.Context, atVersion string) error
Connect(ctx context.Context) error
GetSchema(ctx context.Context, version string) (*Schema, error)
ApplyMigration(ctx context.Context, mi Migration) error
RevertMigration(ctx context.Context, mi Migration) error
}
Gomiger is the interface for the migrator
type GomigerConfig ¶
type GomigerConfig struct {
// Path to the migration root folder.
Path string `yaml:"path"`
// The package name of the migrator & migrations.
// Default by the folder name of the path.
PkgName string `yaml:"pkg_name"`
// Database connection string.
URI string `yaml:"uri"`
// The path to the table / collection schema store.
SchemaStore string `yaml:"schema_store"`
}
GomigerConfig is the global migration module configuration.
func GetGomigerRC ¶
func GetGomigerRC(rcPath string) (*GomigerConfig, error)
GetGomigerRC returns the global migration module configuration
func (*GomigerConfig) ParseYAML ¶
func (rc *GomigerConfig) ParseYAML(path string) error
ParseYAML parse the RC file in YAML format.
func (*GomigerConfig) PopulateAndValidate ¶
func (rc *GomigerConfig) PopulateAndValidate() error
PopulateAndValidate populate data and validate it.
type Migration ¶
type Migration struct {
Version string
Up MutationFunc
Down MutationFunc
}
Migration contain a version name and a mutation function.
type MutationFunc ¶
MutationFunc is a function that applies a migration.
type Schema ¶
type Schema struct {
Version string `json:"version" bson:"version" validate:"required"`
Timestamp time.Time `json:"timestamp" bson:"timestamp" validate:"required"`
Status SchemaStatus `json:"status" bson:"status" validate:"required"`
}
Schema is a log for migrations
type SchemaStatus ¶
type SchemaStatus string
SchemaStatus is the status of the schema
var ( // InProgress is for a running migration InProgress SchemaStatus = "in_progress" // Dirty is for a failed migration Dirty SchemaStatus = "dirty" // Applied is for a completed migration Applied SchemaStatus = "applied" )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gomiger-init
command
Package main is an initialization tool for gomiger, a code generation utility.
|
Package main is an initialization tool for gomiger, a code generation utility. |
|
Package generator provides functionality for generating and managing database migration files.
|
Package generator provides functionality for generating and managing database migration files. |