migrations

package
v0.10.12 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: MIT Imports: 10 Imported by: 0

README

Notes

  • Node operators do not always run their migrations with super user priviledges so you cannot use CREATE EXTENSION

Documentation

Index

Constants

View Source
const (
	// MaxIndividualMigrationTime is the maximum amount of time a single
	// migration is allowed to take before declaring it a failure
	MaxIndividualMigrationTime = 5 * time.Minute
)

Variables

View Source
var (
	// DefaultOptions can be used if you don't want to think about options.
	DefaultOptions = &Options{
		TableName:                 "migrations",
		IDColumnName:              "id",
		IDColumnSize:              255,
		ValidateUnknownMigrations: false,
	}

	// ErrRollbackImpossible is returned when trying to rollback a migration
	// that has no rollback function.
	ErrRollbackImpossible = errors.New("gormigrate: It's impossible to rollback this migration")

	// ErrNoMigrationDefined is returned when no migration is defined.
	ErrNoMigrationDefined = errors.New("gormigrate: No migration defined")

	// ErrMissingID is returned when the ID od migration is equal to ""
	ErrMissingID = errors.New("gormigrate: Missing ID in migration")

	// ErrNoRunMigration is returned when any run migration was found while
	// running RollbackLast
	ErrNoRunMigration = errors.New("gormigrate: Could not find last run migration")

	// ErrMigrationIDDoesNotExist is returned when migrating or rolling back to a migration ID that
	// does not exist in the list of migrations
	ErrMigrationIDDoesNotExist = errors.New("gormigrate: Tried to migrate to an ID that doesn't exist")

	// ErrUnknownPastMigration is returned if a migration exists in the DB that doesn't exist in the code
	ErrUnknownPastMigration = errors.New("gormigrate: Found migration in DB that does not exist in code")
)
View Source
var Migrations []*Migration

Functions

func Migrate

func Migrate(db *gorm.DB) error

func MigrateDown added in v0.10.3

func MigrateDown(db *gorm.DB) error

func MigrateDownFrom added in v0.10.3

func MigrateDownFrom(db *gorm.DB, name string) error

func MigrateUp added in v0.10.3

func MigrateUp(db *gorm.DB, to string) error

func Rollback added in v0.10.3

func Rollback(db *gorm.DB, m *Migration) error

Types

type DuplicatedIDError added in v0.10.5

type DuplicatedIDError struct {
	ID string
}

DuplicatedIDError is returned when more than one migration have the same ID

func (*DuplicatedIDError) Error added in v0.10.5

func (e *DuplicatedIDError) Error() string

type Gormigrate added in v0.10.5

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

Gormigrate represents a collection of all migrations of a database schema.

func New added in v0.10.5

func New(db *gorm.DB, options *Options, migrations []*Migration) *Gormigrate

New returns a new Gormigrate.

func (*Gormigrate) Migrate added in v0.10.5

func (g *Gormigrate) Migrate() error

Migrate executes all migrations that did not run yet.

func (*Gormigrate) MigrateTo added in v0.10.5

func (g *Gormigrate) MigrateTo(migrationID string) error

MigrateTo executes all migrations that did not run yet up to the migration that matches `migrationID`.

func (*Gormigrate) RollbackLast added in v0.10.5

func (g *Gormigrate) RollbackLast() error

RollbackLast undo the last migration

func (*Gormigrate) RollbackMigration added in v0.10.5

func (g *Gormigrate) RollbackMigration(migration *Migration) error

RollbackMigration rolls back a migration.

func (*Gormigrate) RollbackTo added in v0.10.5

func (g *Gormigrate) RollbackTo(migrationID string) error

RollbackTo undoes migrations up to the given migration that matches the `migrationID`. Migration with the matching `migrationID` is not rolled back.

type InitSchemaFunc added in v0.10.5

type InitSchemaFunc func(*gorm.DB) error

InitSchemaFunc is the func signature for initializing the schema.

type Job36 added in v0.10.8

type Job36 struct {
	ID                            int32     `toml:"-" gorm:"primary_key"`
	ExternalJobID                 uuid.UUID `toml:"externalJobID"`
	OffchainreportingOracleSpecID *int32
	CronSpecID                    *int32
	DirectRequestSpecID           *int32
	FluxMonitorSpecID             *int32
	KeeperSpecID                  *int32
	VRFSpecID                     *int32
	WebhookSpecID                 *int32
	PipelineSpecID                int32
	Type                          string
	SchemaVersion                 uint32
	Name                          null.String
	MaxTaskDuration               models.Interval
}

Copy this here to avoid a direct job.Job reference which could change and break the migration.

func (Job36) TableName added in v0.10.8

func (Job36) TableName() string

type MigrateFunc added in v0.10.5

type MigrateFunc func(*gorm.DB) error

MigrateFunc is the func signature for migrating.

type Migration added in v0.10.5

type Migration struct {
	// ID is the migration identifier. Usually a timestamp like "201601021504".
	ID string
	// Migrate is a function that will br executed while running this migration.
	Migrate MigrateFunc
	// Rollback will be executed on rollback. Can be nil.
	Rollback RollbackFunc
	// DisableTransaction disables wrapping the migration in a transaction. Useful in
	// very rare cases, be careful because it can leave the database in an
	// inconsistent state
	DisableTransaction bool
}

Migration represents a database migration (a modification to be made on the database).

func Current added in v0.10.8

func Current(db *gorm.DB) (*Migration, error)

type Options added in v0.10.5

type Options struct {
	// TableName is the migration table.
	TableName string
	// IDColumnName is the name of column where the migration id will be stored.
	IDColumnName string
	// IDColumnSize is the length of the migration id column
	IDColumnSize int
	// ValidateUnknownMigrations will cause migrate to fail if there's unknown migration
	// IDs in the database
	ValidateUnknownMigrations bool
}

Options define options for all migrations.

type ReservedIDError added in v0.10.5

type ReservedIDError struct {
	ID string
}

ReservedIDError is returned when a migration is using a reserved ID

func (*ReservedIDError) Error added in v0.10.5

func (e *ReservedIDError) Error() string

type RollbackFunc added in v0.10.5

type RollbackFunc func(*gorm.DB) error

RollbackFunc is the func signature for rollbacking.

Source Files

Jump to

Keyboard shortcuts

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