migrator

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BSONSingleFieldIndexKeyEquals added in v0.1.7

func BSONSingleFieldIndexKeyEquals(key bson.D, field string, direction int32) bool

func DefaultOwnerID

func DefaultOwnerID(hostname string) string

func IsMongoDuplicateKeyError added in v0.1.7

func IsMongoDuplicateKeyError(err error) bool

func TargetVersion

func TargetVersion(list []Migration) int64

Types

type LockAcquireInfo added in v0.1.8

type LockAcquireInfo struct {
	Acquired       bool
	Created        bool
	Takeover       bool
	PrevOwner      string
	PrevLeaseUntil time.Time
	NewOwner       string
	NewLeaseUntil  time.Time
}

type Locker

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

func NewLocker

func NewLocker(db *mongo.Database, lockKey, owner string, leaseFor time.Duration) *Locker

func (*Locker) Release

func (l *Locker) Release(ctx context.Context) error

func (*Locker) Renew

func (l *Locker) Renew(ctx context.Context) error

func (*Locker) TryAcquire

func (l *Locker) TryAcquire(ctx context.Context) (bool, error)

func (*Locker) TryAcquireWithInfo added in v0.1.8

func (l *Locker) TryAcquireWithInfo(ctx context.Context) (LockAcquireInfo, error)

type Manager

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

func NewManager

func NewManager(db *mongo.Database, owner string, cfg ManagerConfig) *Manager

func (*Manager) LastError

func (m *Manager) LastError() string

func (*Manager) Ready

func (m *Manager) Ready() bool

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, list []Migration) error

type ManagerConfig added in v0.1.7

type ManagerConfig struct {
	LockKey          string // e.g. identityservice:migrations
	LeaseFor         time.Duration
	PollInterval     time.Duration
	OpTimeout        time.Duration // OpTimeout (locks, reads/writes)
	MigrationTimeout time.Duration // MigrationTimeout (long-running migrations)

	Logger *logrus.Entry

	FailFast      bool // true — Run error
	WaitForLeader bool // true — not ready, while leader not accept target
}

type Migration

type Migration struct {
	Version int64
	Name    string
	Up      func(ctx context.Context, db *mongo.Database) error
}

func ValidateAndSort

func ValidateAndSort(list []Migration) ([]Migration, error)

type MongoIndexInfo added in v0.1.7

type MongoIndexInfo struct {
	Name   string `bson:"name"`
	Key    bson.D `bson:"key"`
	Unique bool   `bson:"unique,omitempty"`
}

func ListMongoIndexes added in v0.1.7

func ListMongoIndexes(ctx context.Context, col *mongo.Collection) ([]MongoIndexInfo, error)

type MongoIndexState added in v0.1.7

type MongoIndexState int
const (
	MongoIndexAbsent MongoIndexState = iota
	MongoIndexUnique
	MongoIndexNonUnique
)

func MongoSingleFieldIndexState added in v0.1.7

func MongoSingleFieldIndexState(indexes []MongoIndexInfo, field string, direction int32, desiredName string) (state MongoIndexState, existingName string, err error)

MongoSingleFieldIndexState: index with other desiredName, but other key-spec -> error, if exists by {field: direction}:

  • unique -> MongoIndexUnique
  • not unique -> MongoIndexNonUnique

type MongoUniqueStringFieldDiagnostics added in v0.1.7

type MongoUniqueStringFieldDiagnostics struct {
	DuplicateStrings []bson.M
	NullCount        int64
}

func DiagnoseMongoUniqueStringField added in v0.1.7

func DiagnoseMongoUniqueStringField(ctx context.Context, col *mongo.Collection, field string, limit int) (MongoUniqueStringFieldDiagnostics, error)

DiagnoseMongoUniqueStringField:

  • field duplicates (limit)
  • documents with field=null

Jump to

Keyboard shortcuts

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