schema

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MPL-2.0 Imports: 11 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, opt ...Option) (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. Supports the WithMigrationStates(...) option.

func TestCloneMigrationStates added in v0.2.0

func TestCloneMigrationStates(t *testing.T) map[string]migrationState

func TestCreatePartialMigrationState added in v0.2.0

func TestCreatePartialMigrationState(om migrationState, maxVer int) migrationState

Creates a new migrationState only with the versions <= the provided maxVer

Types

type LogEntry added in v0.2.0

type LogEntry struct {
	Id               int
	MigrationVersion string
	CreateTime       time.Time
	Entry            string
}

LogEntry represents a log entry generated during migrations.

func GetMigrationLog added in v0.2.0

func GetMigrationLog(ctx context.Context, d *sql.DB, opt ...Option) ([]LogEntry, error)

GetMigrationLog will retrieve the migration logs from the db for the last migration. Once it's read the entries, it will delete them from the database.

The WithDeleteLog option is supported and will remove all log entries when provided.

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, opt ...Option) (*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 Option added in v0.2.0

type Option func(*options)

Option - how Options are passed as arguments.

func WithDeleteLog added in v0.2.0

func WithDeleteLog(del bool) Option

WithDeleteLog provides an option to specify the deletion of log entries.

func WithMigrationStates added in v0.2.0

func WithMigrationStates(states map[string]migrationState) Option

WithMigrationStates provides an optional migration states.

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