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 ¶
- Variables
- func ConvertDBError(err error, itemID interface{}) error
- func InitInfoTable(db *sql.DB) error
- func Set(newMigrations []Migration)
- func SetDBVersion(db *sql.DB, dbDriver types.DBDriver, targetVer Version) error
- type ForeignKeyError
- type ItemNotFoundError
- type Migration
- type Step
- type TableAlreadyExistsError
- type TableNotFoundError
- type ValidationError
- type Version
Constants ¶
This section is empty.
Variables ¶
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 ¶
ConvertDBError converts sql errors to those defined in this package
func InitInfoTable ¶
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.
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 Step ¶
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 ¶
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.