Documentation
¶
Overview ¶
Package core provides the main migration functionality for gomiger
Index ¶
- type BaseMigrator
- func (b *BaseMigrator) ApplyMigration(_ context.Context, _ Migration) error
- func (b *BaseMigrator) Connect(_ context.Context) error
- func (b *BaseMigrator) Down(ctx context.Context, atVersion string) error
- func (b *BaseMigrator) GetSchema(_ context.Context, _ string) (*Schema, error)
- func (b *BaseMigrator) RevertMigration(_ context.Context, _ Migration) error
- func (b *BaseMigrator) Up(ctx context.Context, toVersion string) error
- type Gomiger
- type GomigerConfig
- type Migration
- type MutationFunc
- type Schema
- type SchemaStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseMigrator ¶
type BaseMigrator struct {
Migrations []Migration
}
BaseMigrator is the base migrator for controlling flow. It does not connect or execute to any database.
func (*BaseMigrator) ApplyMigration ¶
func (b *BaseMigrator) ApplyMigration(_ context.Context, _ Migration) error
ApplyMigration applies a migration.
func (*BaseMigrator) Connect ¶
func (b *BaseMigrator) Connect(_ context.Context) error
Connect connects to the database.
func (*BaseMigrator) Down ¶
func (b *BaseMigrator) Down(ctx context.Context, atVersion string) error
Down reverts the database to a specific version.
func (*BaseMigrator) RevertMigration ¶
func (b *BaseMigrator) RevertMigration(_ context.Context, _ Migration) error
RevertMigration reverts a migration.
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. |
|
mg
command
THIS FILE IS GENERATED BY GOMIGER.
|
THIS FILE IS GENERATED BY GOMIGER. |
|
scripts/gen_contents
command
Package main provides a generator script that creates the contents.mg.go file.
|
Package main provides a generator script that creates the contents.mg.go file. |