mongodb

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultLockIndexName = "lock_unique_key"

DefaultLockIndexName is the default name of the index which adds unique constraint to the locking_key field.

View Source
const DefaultLockingCollection = "migrate_advisory_lock"

DefaultLockingCollection is the collection to use for advisory locking by default.

View Source
const DefaultMigrationsCollection = "schema_migrations"

DefaultMigrationsCollection is the collection to use for migration state by default.

Variables

View Source
var (
	// ErrNoDatabaseName signals a missing database name.
	ErrNoDatabaseName = fmt.Errorf("no database name")
	// ErrNoDatabaseClient signals a missing database client.
	ErrNoDatabaseClient = fmt.Errorf("no database client")
	// ErrDatabaseLocked signals that the database is already locked by another migration process.
	ErrDatabaseLocked = fmt.Errorf("database is locked")
)

Functions

func NewDriver

func NewDriver(client *mongo.Client, database string, opts ...DriverOption) (lightmigrate.MigrationDriver, error)

NewDriver instantiates a new MongoDB driver. A MongoDB client and the database name are required arguments.

Types

type DriverOption

type DriverOption func(svc *driver)

DriverOption is a function that can be used within the driver constructor to modify the driver object.

func WithLocking

func WithLocking(lockConfig LockingConfig) DriverOption

WithLocking can be used to configure the locking behaviour of the MongoDB migration driver. See LockingConfig for details.

func WithLogger

func WithLogger(logger lightmigrate.Logger) DriverOption

WithLogger sets the logging instance used by the driver.

func WithMigrationCollection

func WithMigrationCollection(migrationCollection string) DriverOption

WithMigrationCollection allows to specify the name of the collection that contains the migration state.

func WithTransactions

func WithTransactions(transactions bool) DriverOption

WithTransactions allows enabling or disabling MongoDB transactions for the migration process.

func WithVerboseLogging

func WithVerboseLogging(verbose bool) DriverOption

WithVerboseLogging sets the verbose flag of the driver.

type LockingConfig

type LockingConfig struct {
	// CollectionName is the collection name where the lock object will be stored. Defaults to DefaultLockingCollection.
	CollectionName string
	// IndexName is the name of the unique index that is required for the locking process.
	// Defaults to DefaultLockIndexName.
	IndexName string
	// Enabled flag can be used to enable or disable locking, by default it is disabled.
	Enabled bool
}

LockingConfig can be used to configure the locking behaviour of the MongoDB migration driver.

Jump to

Keyboard shortcuts

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