schema

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2021 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySchemaVersion

func BinarySchemaVersion(dialect string) int

BinarySchemaVersion provides the schema version that this binary supports for the provided dialect. If the binary doesn't support this dialect -1 is returned.

func MigrateStore

func MigrateStore(ctx context.Context, dialect string, url string) (bool, error)

MigrateStore executes the migrations needed to initialize the store. It returns true if migrations actually ran; false if the database is already current or if there was an error.

Types

type Manager

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

Manager provides a way to run operations and retrieve information regarding the underlying boundary database schema. Manager is not thread safe.

func NewManager

func NewManager(ctx context.Context, dialect string, db *sql.DB) (*Manager, error)

NewManager creates a new schema manager. An error is returned if the provided dialect is unrecognized or if the passed in db is unreachable.

func (*Manager) CurrentState

func (b *Manager) CurrentState(ctx context.Context) (*State, error)

CurrentState provides the state of the boundary schema contained in the backing database.

func (*Manager) ExclusiveLock

func (b *Manager) ExclusiveLock(ctx context.Context) error

ExclusiveLock attempts to obtain an exclusive lock on the database. An error is returned if a lock was unable to be obtained.

func (*Manager) ExclusiveUnlock

func (b *Manager) ExclusiveUnlock(ctx context.Context) error

ExclusiveUnlock releases a shared lock on the database. If this fails for whatever reason an error is returned. Unlocking a lock that is not held is not an error.

func (*Manager) RollForward

func (b *Manager) RollForward(ctx context.Context) error

RollForward updates the database schema to match the latest version known by the boundary binary. An error is not returned if the database is already at the most recent version.

func (*Manager) SharedLock

func (b *Manager) SharedLock(ctx context.Context) error

SharedLock attempts to obtain a shared lock on the database. This can fail if an exclusive lock is already held. If the lock can't be obtained an error is returned.

func (*Manager) SharedUnlock

func (b *Manager) SharedUnlock(ctx context.Context) error

SharedUnlock releases a shared lock on the database. If this fails for whatever reason an error is returned. Unlocking a lock that is not held is not an error.

type State

type State struct {
	// InitializationStarted indicates if the current database has been initialized previously.
	InitializationStarted bool
	// Dirty is set to true if the database failed in a previous migration/initialization.
	Dirty bool
	// DatabaseSchemaVersion is the schema version that is currently running in the database.
	DatabaseSchemaVersion int
	// BinarySchemaVersion is the schema version which this boundary binary supports.
	BinarySchemaVersion int
}

State contains information regarding the current state of a boundary database's schema.

Directories

Path Synopsis
migrations

Jump to

Keyboard shortcuts

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