mongomigrate

package
v0.0.0-...-4410c1d Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCLI

func GetCLI(m *Mongomigrate) *cli.App

GetCLI returns the mongomigrate CLI

Types

type Config

type Config struct {
	Database struct {
		Hostname string `mapstructure:"hostname"`
		Port     string `mapstructure:"port"`
		DB       string `mapstructure:"db"`
		Username string `mapstructure:"username"`
		Password string `mapstructure:"password"`
	} `mapstructure:"database"`
	Migrations struct {
		DB         string `mapstructure:"db"`
		Collection string `mapstructure:"collection"`
	} `mapstructure:"migrations"`
}

Config holds the configuration for mongomigrate

func NewConfig

func NewConfig(filepath string) (*Config, error)

NewConfig reads the given configuration file and the environment and returns a newly created Config An error is returned if a field was not found in the configuration (file or env)

func (*Config) BuildMongoDBConnexionString

func (c *Config) BuildMongoDBConnexionString() string

BuildMongoDBConnexionString returns the mongoDB connexion url

type ErrKeyNotFound

type ErrKeyNotFound struct {
	Key string
}

ErrKeyNotFound is an error indicating that a configuration field has not been found in the environment

func NewErrKeyNotFound

func NewErrKeyNotFound(key string) *ErrKeyNotFound

NewErrKeyNotFound returns a new ErrNewErrKeyNotFound with the given key

func (*ErrKeyNotFound) Error

func (e *ErrKeyNotFound) Error() string

Error returns the error message It makes ErrKeyNotFound implements the Error interface

type MigrateFunc

type MigrateFunc func(ctx context.Context, db *mongo.Database) error

MigrateFunc is a migrate function

type Migration

type Migration struct {
	ID       uint64
	Name     string
	Migrate  MigrateFunc
	Rollback RollbackFunc
}

Migration represents a migration

type Mongomigrate

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

Mongomigrate is a struct holding the migrations

func New

func New(db *mongo.Database, collectionName string, migrations []*Migration, seeders []*Seeder) *Mongomigrate

New is a constructor for Mongomigrate

func (*Mongomigrate) IsApplied

func (m *Mongomigrate) IsApplied(ctx context.Context, migration *Migration) bool

IsApplied returns true if the given migration has already been applied

func (*Mongomigrate) MigrateTo

func (m *Mongomigrate) MigrateTo(ctx context.Context, migrationIndex int) error

MigrateTo runs the first migrationIndex migrations

func (*Mongomigrate) RollbackTo

func (m *Mongomigrate) RollbackTo(ctx context.Context, migrationIndex int) error

RollbackTo rolls back the last migrationIndex migrations

func (*Mongomigrate) SeedByRegex

func (m *Mongomigrate) SeedByRegex(ctx context.Context, regex string) error

SeedByRegex runs the seeders whose names contains the given regex

func (*Mongomigrate) SeedTo

func (m *Mongomigrate) SeedTo(ctx context.Context, n int) error

SeedTo runs the first n seeders

func (*Mongomigrate) SetVersion

func (m *Mongomigrate) SetVersion(ctx context.Context, migration *Migration) error

SetVersion inserts a new version record in the migrations collection If the given version is 0, nothing happens

type RollbackFunc

type RollbackFunc func(ctx context.Context, db *mongo.Database) error

RollbackFunc is a rollback function

type SeedFunc

type SeedFunc func(ctx context.Context, db *mongo.Database) error

SeedFunc represents a operation that seeds the database

type Seeder

type Seeder struct {
	Name string
	Seed SeedFunc
}

Seeder holds a seed function and a name

Jump to

Keyboard shortcuts

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