Documentation
¶
Index ¶
- func GetCLI(m *Mongomigrate) *cli.App
- type Config
- type ErrKeyNotFound
- type MigrateFunc
- type Migration
- type Mongomigrate
- func (m *Mongomigrate) IsApplied(ctx context.Context, migration *Migration) bool
- func (m *Mongomigrate) MigrateTo(ctx context.Context, migrationIndex int) error
- func (m *Mongomigrate) RollbackTo(ctx context.Context, migrationIndex int) error
- func (m *Mongomigrate) SeedByRegex(ctx context.Context, regex string) error
- func (m *Mongomigrate) SeedTo(ctx context.Context, n int) error
- func (m *Mongomigrate) SetVersion(ctx context.Context, migration *Migration) error
- type RollbackFunc
- type SeedFunc
- type Seeder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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 ¶
RollbackFunc is a rollback function