migrate

package
v0.9.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultOptions = &Options{
		DatabaseName:              "convoy",
		CollectionName:            "data_migrations",
		ValidateUnknownMigrations: true,
		UseTransaction:            true,
	}

	// ErrRollbackImpossible is returned when trying to rollback a migration
	// that has no rollback function.
	ErrRollbackImpossible = errors.New("migrate: It's impossible to rollback this migration")

	// ErrNoMigrationDefined is returned when no migration is defined.
	ErrNoMigrationDefined = errors.New("migrate: No migration defined")

	// ErrMissingID is returned when the ID of the migration is equal to ""
	ErrMissingID = errors.New("migrate: Missing ID in migration")

	// ErrNoRunMigration is returned when any run migration was found while
	// running RollbackLast
	ErrNoRunMigration = errors.New("migrate: Could not find last run migration")

	// ErrUnknownPastMigration is returned if a migration exists in the DB that doesn't exist in the code
	ErrUnknownPastMigration = errors.New("migrate: Found migration in DB that does not exist in code")

	// ErrMigrationIDDoesNotExist is returned when migrating or rolling back to a migration ID that
	// does not exist in the list of migrations
	ErrMigrationIDDoesNotExist = errors.New("migrate: Tried to migrate to an ID that doesn't exist")

	// ErrPendingMigrationsFound is used to indicate there exist pending migrations yet to be run
	// if the user proceeds without running migrations it can lead to data integrity issues.
	ErrPendingMigrationsFound = errors.New("migrate: Pending migrations exist, please run convoy migrate first")
)

Functions

This section is empty.

Types

type DuplicatedIDError

type DuplicatedIDError struct {
	ID string
}

DuplicatedIDError is returned when more than one migration have the same ID

func (*DuplicatedIDError) Error

func (e *DuplicatedIDError) Error() string

type InitSchemaFunc

type InitSchemaFunc func(context.Context, *mongo.Database) (bool, error)

type MigrateFunc

type MigrateFunc func(*mongo.Database) error

type Migration

type Migration struct {
	// ID is the migration identifier. Usually a timestamp like "201601021504".
	ID string
	// Migrate is a function that will br executed while running this migration.
	Migrate MigrateFunc
	// Rollback will be executed on rollback. Can be nil.
	Rollback RollbackFunc
}

type MigrationDoc

type MigrationDoc struct {
	ID string `json:"id" bson:"id"`
}

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(c *mongo.Client, opts *Options, migrations []*Migration, i InitSchemaFunc) *Migrator

func (*Migrator) CheckPendingMigrations

func (m *Migrator) CheckPendingMigrations(ctx context.Context) (bool, error)

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context) error

Migrate executes all migrations that did not run yet.

func (*Migrator) MigrateTo

func (m *Migrator) MigrateTo(ctx context.Context, migrationID string) error

MigrateTo executes all migrations that did not run yet up to the migration that matches `migrationID`.

func (*Migrator) RollbackLast

func (m *Migrator) RollbackLast(ctx context.Context) error

RollbackLast undo the last migration

func (*Migrator) RollbackTo

func (m *Migrator) RollbackTo(ctx context.Context, migrationID string) error

RollbackTo undoes migrations up to the given migration that matches the `migrationID`. Migration with the matching `migrationID` is not rolled back.

type Options

type Options struct {
	// DatabaseName is the name of the database to connect.
	DatabaseName string

	// CollectionName is the migration table.
	CollectionName string

	// ValidateUnknownMigrations will cause migrate to fail if there are unknown migration
	// IDs in the database
	ValidateUnknownMigrations bool

	// UseTransaction executes migrations inside a single transaction.
	UseTransaction bool
}

type RollbackFunc

type RollbackFunc func(*mongo.Database) error

Jump to

Keyboard shortcuts

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