Documentation
¶
Overview ¶
Package schemaver provides a way to manage your data schema version.
Index ¶
Constants ¶
const ( // NoVersion will be set as version value by Initialize. NoVersion = "none" // BadVersion must be set as version value in case data schema may // be incorrect (as result of interrupted migration or restoring // backup). BadVersion = "dirty" // EnvLocation must contain url pointing to location of data // schema version. For example: file:///some/path/. EnvLocation = "NARADA4D" // EnvSkipLock must be set to non-empty value in case // ExclusiveLock was already acquired (by parent process). EnvSkipLock = "NARADA4D_SKIP_LOCK" )
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
func Initialize() error
Initialize initialize version at location provided in $NARADA4D.
Version must not be already initialized.
func RegisterProtocol ¶
RegisterProtocol must be called by packages which implement some protocol before first call to Initialize or New.
Types ¶
type Backend ¶
type Backend struct {
// New returns implementation of SchemaVerBackend working with
// version at given location or error if location is incorrect.
New func(*url.URL) (Manage, error)
// Initialize version at given location or return error if
// location is incorrect or already initialized.
Initialize func(*url.URL) error
}
Backend used for registering backend implementing concrete protocol.
type Manage ¶
type Manage interface {
//
// If called with already acquired lock previous lock may be
// released before acquiring new one.
SharedLock()
// ExclusiveLock must acquire exclusive lock on version value.
//
// If called with already acquired lock previous lock may be
// released before acquiring new one.
ExclusiveLock()
// Unlock will be called after SharedLock or ExclusiveLock and
// must release lock on version value.
Unlock()
// Get will be called after SharedLock or ExclusiveLock and must
// return current version.
Get() string
// Set will be called after ExclusiveLock and must change current
// version.
Set(string)
// Close will release any resources used to manage schema version.
Close() error
}
Manage interface must be implemented by concrete data schema version managing protocols.
type SchemaVer ¶
type SchemaVer struct {
// contains filtered or unexported fields
}
SchemaVer manage data schema versions.
func New ¶
New creates object for managing data schema version at location provided in $NARADA4D.
Version must be already initialized.
func (*SchemaVer) AddCallback ¶
AddCallback registers user-provided function which will be called with current version in parameter by each SharedLock or ExclusiveLock before they returns.
Usually this function should check is current version is supported by this application and call log.Fatal if not.
func (*SchemaVer) Close ¶ added in v1.2.0
Close release any resources used to manage schema version.
No other methods should be called after Close.
func (*SchemaVer) ExclusiveLock ¶
ExclusiveLock acquire exclusive lock and return current version.
It may be called recursively, under already acquired ExclusiveLock (in this case it'll do nothing).
func (*SchemaVer) Get ¶
Get returns current version.
It must be called under SharedLock or ExclusiveLock.
func (*SchemaVer) SharedLock ¶
SharedLock acquire shared lock and return current version.
It may be called recursively, under already acquired SharedLock or ExclusiveLock (in this case it'll do nothing).