Documentation ¶
Index ¶
Constants ¶
View Source
const CollectionName = "cis:schema"
CollectionName is the name of the mongo-db collection used to store schema migrations.
Variables ¶
View Source
var Default = NewRegistry()
Default is the default schema registry and used by package level functions Add and ApplyMigrations.
View Source
var (
ErrNotFound = errors.New("not found")
)
Common error messages when working with the schema package:.
Functions ¶
Types ¶
type Database ¶
type Database interface { // Load should return the migration record stored at key. Load(ctx context.Context, key string) (*MigrationRecord, error) // Save should create a new migration record for key and version // overwritting any previously created migration record with the // same key. Save(ctx context.Context, key, version string) error }
Database stores schema and applied migrations.
type MigrateFunc ¶
MigrateFunc is the function called to perform the migration between the versions from and to.
type Migration ¶
type Migration struct { // Description provides a short description of the migration. Description string // Key identifies the subsystem / migratable part this migration is // for. Key string // Version is the semver that requires this migration to be run. Version string // MigrateFunc is called when the migration is applied. MigrateFunc MigrateFunc // BackupCollections can be set to a list of collection names // that should be dumped to disk prior to calling MigrateFunc. // In case an error is returned by MigrateFunc, all collections // listed here are dropped and re-created from the saved dump. BackupCollections []string }
type MigrationRecord ¶
type MigrationRecord struct { // Key is the key of the subsystem the migration applies to. Key string `json:"key" bson:"key"` // Version is the version of the subsystem after this migration // executed. Version string `json:"version" bson:"version"` // MigratedAt holds the time the migration was applied. MigratedAt time.Time `json:"migratedAt" bson:"migratedAt"` }
MigrationRecord defines the record stored in the mongodb schema collection and represents a successfully applied migration.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
Click to show internal directories.
Click to hide internal directories.