migrations

package
v1.24.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package migrations contains an implementation of a simple database migration mechanism that allows semi-automatic transitions between various database versions as well as building the latest version of the database from scratch.

Please look into README.md with further instructions how to use it.

Index

Constants

This section is empty.

Variables

View Source
var ErrOldReport = types.ErrOldReport

ErrOldReport is an error returned if a more recent already exists on the storage while attempting to write a report for a cluster.

Functions

func ConvertDBError

func ConvertDBError(err error, itemID interface{}) error

ConvertDBError converts sql errors to those defined in this package

func InitInfoTable

func InitInfoTable(db *sql.DB) error

InitInfoTable ensures that the migration information table is created. If it already exists, no changes will be made to the database. Otherwise, a new migration information table will be created and initialized.

func Set

func Set(newMigrations []Migration)

Set initialized this package by setting the migrations steps to 'newMigrations' It is mandatory to call this function before using this package

func SetDBVersion

func SetDBVersion(db *sql.DB, dbDriver types.DBDriver, targetVer Version) error

SetDBVersion attempts to get the database into the specified target version using available migration steps.

Types

type ForeignKeyError

type ForeignKeyError struct {
	TableName      string
	ForeignKeyName string

	// Details can reveal you information about specific item violating fk
	Details string
}

ForeignKeyError something violates foreign key error tableName and foreignKeyName can be empty for DBs not supporting it (SQLite)

func (*ForeignKeyError) Error

func (err *ForeignKeyError) Error() string

Error returns error string

type ItemNotFoundError

type ItemNotFoundError = types.ItemNotFoundError

ItemNotFoundError shows that item with id ItemID wasn't found in the storage

type Migration

type Migration struct {
	StepUp   Step
	StepDown Step
}

Migration type describes a single Migration.

type Step

type Step func(tx *sql.Tx, driver types.DBDriver) error

Step represents an action performed to either increase or decrease the migration version of the database.

type TableAlreadyExistsError

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

TableAlreadyExistsError represents table already exists error

func (*TableAlreadyExistsError) Error

func (err *TableAlreadyExistsError) Error() string

Error returns error string

type TableNotFoundError

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

TableNotFoundError table not found error

func (*TableNotFoundError) Error

func (err *TableNotFoundError) Error() string

Error returns error string

type ValidationError

type ValidationError = types.ValidationError

ValidationError validation error, for example when string is longer then expected

type Version

type Version uint

Version represents a version of the database.

func GetDBVersion

func GetDBVersion(db *sql.DB) (Version, error)

GetDBVersion reads the current version of the database from the migration info table.

func GetMaxVersion

func GetMaxVersion() Version

GetMaxVersion returns the highest available migration version. The DB version cannot be set to a value higher than this. This value is equivalent to the length of the list of available migrations.

Jump to

Keyboard shortcuts

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