Documentation
¶
Index ¶
- Variables
- func CreateIndexes(ctx context.Context, coll *mongo.Collection, models ...mongo.IndexModel) error
- func CreateIndexesWithOptions(ctx context.Context, coll *mongo.Collection, opts []IndexCreateOption, ...) error
- func DropIndexes(ctx context.Context, coll *mongo.Collection, names ...string) error
- func EnsureCollection(ctx context.Context, db *mongo.Database, name string, opts ...CollectionOption) (*mongo.Collection, error)
- func FormatStatusTable(status []MigrationStatus) string
- func GetMigrations(filters ...MigrationFilter) map[string]Migration
- func MustRegister(ms ...Migration)
- func Register(m Migration) error
- func RegisteredMigrations() map[string]Migration
- type ChecksumDrift
- type CollectionOption
- func WithCapped(maxBytes int64, maxDocs int64) CollectionOption
- func WithTimeSeries(timeField string, metaField string, granularity string) CollectionOption
- func WithValidationAction(action string) CollectionOption
- func WithValidationLevel(level string) CollectionOption
- func WithValidator(validator interface{}) CollectionOption
- type Direction
- type Engine
- func (e *Engine) ChecksumDrifts(ctx context.Context) ([]ChecksumDrift, error)
- func (e *Engine) Down(ctx context.Context, target string) error
- func (e *Engine) Force(ctx context.Context, version string) error
- func (e *Engine) ForceUnlock(ctx context.Context) error
- func (e *Engine) GetLockInfo(ctx context.Context) (LockInfo, error)
- func (e *Engine) GetStatus(ctx context.Context) ([]MigrationStatus, error)
- func (e *Engine) ListApplied(ctx context.Context) ([]MigrationRecord, error)
- func (e *Engine) Plan(ctx context.Context, direction Direction, target string) ([]string, error)
- func (e *Engine) SetLogger(logger *slog.Logger)
- func (e *Engine) Up(ctx context.Context, target string) error
- type ErrNotSupported
- type Generator
- type IndexBuilder
- func (b *IndexBuilder) Key(field string, order interface{}) *IndexBuilder
- func (b *IndexBuilder) Model() mongo.IndexModel
- func (b *IndexBuilder) Name(name string) *IndexBuilder
- func (b *IndexBuilder) Partial(expr interface{}) *IndexBuilder
- func (b *IndexBuilder) Sparse() *IndexBuilder
- func (b *IndexBuilder) TTL(seconds int32) *IndexBuilder
- func (b *IndexBuilder) Unique() *IndexBuilder
- type IndexCreateOption
- type IndexKey
- type LockInfo
- type Migration
- type MigrationFilter
- type MigrationMetadata
- type MigrationRecord
- type MigrationStatus
- type SchemaBuilder
- func (s *SchemaBuilder) Array(items any) bson.M
- func (s *SchemaBuilder) Bool() bson.M
- func (s *SchemaBuilder) BsonType(t string) *SchemaBuilder
- func (s *SchemaBuilder) Build() bson.M
- func (s *SchemaBuilder) Date() bson.M
- func (s *SchemaBuilder) Field(name string, props any) *SchemaBuilder
- func (s *SchemaBuilder) Int() bson.M
- func (s *SchemaBuilder) Long() bson.M
- func (s *SchemaBuilder) Object(props bson.M) bson.M
- func (s *SchemaBuilder) Properties(props bson.M) *SchemaBuilder
- func (s *SchemaBuilder) Required(fields ...string) *SchemaBuilder
- func (s *SchemaBuilder) String() bson.M
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCollectionNameRequired = errors.New("collection name is required") ErrCreateCollectionFailed = errors.New("create collection failed") ErrListCollectionsFailed = errors.New("list collections failed") )
View Source
var ( ErrFailedToLock = errors.New("could not acquire migration lock; another process may be running") ErrChecksumMismatch = errors.New("migration checksum mismatch") ErrUnknownMigration = errors.New("migration not registered") )
View Source
var ( ErrFailedToCreateFile = errors.New("failed to create file") ErrFailedToParseTemplate = errors.New("failed to parse template") ErrFailedToExecuteTemplate = errors.New("failed to execute template") )
Functions ¶
func CreateIndexes ¶
func CreateIndexes(ctx context.Context, coll *mongo.Collection, models ...mongo.IndexModel) error
func CreateIndexesWithOptions ¶
func CreateIndexesWithOptions( ctx context.Context, coll *mongo.Collection, opts []IndexCreateOption, indexes ...*IndexBuilder, ) error
func DropIndexes ¶
func EnsureCollection ¶
func EnsureCollection(ctx context.Context, db *mongo.Database, name string, opts ...CollectionOption) (*mongo.Collection, error)
func FormatStatusTable ¶
func FormatStatusTable(status []MigrationStatus) string
func GetMigrations ¶
func GetMigrations(filters ...MigrationFilter) map[string]Migration
func MustRegister ¶
func MustRegister(ms ...Migration)
func RegisteredMigrations ¶
Types ¶
type ChecksumDrift ¶
type CollectionOption ¶
type CollectionOption func(*options.CreateCollectionOptionsBuilder)
func WithCapped ¶
func WithCapped(maxBytes int64, maxDocs int64) CollectionOption
func WithTimeSeries ¶
func WithTimeSeries(timeField string, metaField string, granularity string) CollectionOption
func WithValidationAction ¶
func WithValidationAction(action string) CollectionOption
func WithValidationLevel ¶
func WithValidationLevel(level string) CollectionOption
func WithValidator ¶
func WithValidator(validator interface{}) CollectionOption
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func NewEngineWithMigrations ¶
func (*Engine) ChecksumDrifts ¶
func (e *Engine) ChecksumDrifts(ctx context.Context) ([]ChecksumDrift, error)
func (*Engine) GetStatus ¶
func (e *Engine) GetStatus(ctx context.Context) ([]MigrationStatus, error)
GetStatus returns a full snapshot of registered migrations and their status.
func (*Engine) ListApplied ¶
func (e *Engine) ListApplied(ctx context.Context) ([]MigrationRecord, error)
type ErrNotSupported ¶
type ErrNotSupported struct {
Operation string
}
func (ErrNotSupported) Error ¶
func (e ErrNotSupported) Error() string
type IndexBuilder ¶
type IndexBuilder struct {
// contains filtered or unexported fields
}
func Index ¶
func Index(keys ...IndexKey) *IndexBuilder
func (*IndexBuilder) Key ¶
func (b *IndexBuilder) Key(field string, order interface{}) *IndexBuilder
func (*IndexBuilder) Model ¶
func (b *IndexBuilder) Model() mongo.IndexModel
func (*IndexBuilder) Name ¶
func (b *IndexBuilder) Name(name string) *IndexBuilder
func (*IndexBuilder) Partial ¶
func (b *IndexBuilder) Partial(expr interface{}) *IndexBuilder
func (*IndexBuilder) Sparse ¶
func (b *IndexBuilder) Sparse() *IndexBuilder
func (*IndexBuilder) TTL ¶
func (b *IndexBuilder) TTL(seconds int32) *IndexBuilder
func (*IndexBuilder) Unique ¶
func (b *IndexBuilder) Unique() *IndexBuilder
type IndexCreateOption ¶
type IndexCreateOption func(*indexCreateConfig)
func WithIndexNameOverride ¶
func WithIndexNameOverride(fn func(string) string) IndexCreateOption
func WithIndexNamePrefix ¶
func WithIndexNamePrefix(prefix string) IndexCreateOption
func WithIndexNameSuffix ¶
func WithIndexNameSuffix(suffix string) IndexCreateOption
type LockInfo ¶
type LockInfo struct {
Active bool `json:"active"`
LockID string `json:"lock_id,omitempty" bson:"lock_id,omitempty"`
Host string `json:"host,omitempty" bson:"host,omitempty"`
PID int `json:"pid,omitempty" bson:"pid,omitempty"`
AcquiredAt time.Time `json:"acquired_at,omitempty" bson:"acquired_at,omitempty"`
}
type MigrationFilter ¶
type MigrationMetadata ¶
type MigrationRecord ¶
type MigrationRecord struct {
Version string `json:"version" bson:"version"`
Description string `json:"description" bson:"description"`
AppliedAt time.Time `json:"applied_at" bson:"applied_at"`
Checksum string `json:"checksum" bson:"checksum"`
}
MigrationRecord captures an applied migration entry for opslog output.
type MigrationStatus ¶
type SchemaBuilder ¶
type SchemaBuilder struct {
// contains filtered or unexported fields
}
func Schema ¶
func Schema() *SchemaBuilder
func (*SchemaBuilder) Bool ¶
func (s *SchemaBuilder) Bool() bson.M
func (*SchemaBuilder) BsonType ¶
func (s *SchemaBuilder) BsonType(t string) *SchemaBuilder
func (*SchemaBuilder) Build ¶
func (s *SchemaBuilder) Build() bson.M
func (*SchemaBuilder) Date ¶
func (s *SchemaBuilder) Date() bson.M
func (*SchemaBuilder) Field ¶
func (s *SchemaBuilder) Field(name string, props any) *SchemaBuilder
func (*SchemaBuilder) Int ¶
func (s *SchemaBuilder) Int() bson.M
func (*SchemaBuilder) Long ¶
func (s *SchemaBuilder) Long() bson.M
func (*SchemaBuilder) Properties ¶
func (s *SchemaBuilder) Properties(props bson.M) *SchemaBuilder
func (*SchemaBuilder) Required ¶
func (s *SchemaBuilder) Required(fields ...string) *SchemaBuilder
func (*SchemaBuilder) String ¶
func (s *SchemaBuilder) String() bson.M
Click to show internal directories.
Click to hide internal directories.