Documentation ¶
Index ¶
Constants ¶
const DefaultLockIndexName = "lock_unique_key"
DefaultLockIndexName is the default name of the index which adds unique constraint to the locking_key field.
const DefaultLockingCollection = "migrate_advisory_lock"
DefaultLockingCollection is the collection to use for advisory locking by default.
const DefaultMigrationsCollection = "schema_migrations"
DefaultMigrationsCollection is the collection to use for migration state by default.
Variables ¶
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.