migrate

package
v0.0.50 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package migration allows to perform versioned migrations in your ArangoDB.

Index

Constants

View Source
const AllAvailable = -1

AllAvailable used in "Up" or "Down" methods to run all available migrations.

Variables

This section is empty.

Functions

func HasVersion

func HasVersion(migrations []Migration, version uint64) bool

Types

type Migration

type Migration struct {
	Version     uint64
	Description string
	Up          MigrationFunc
	Down        MigrationFunc
}

Migration represents single engine migration. Migration contains:

- version: migration version, must be unique in migration list

- description: text description of migration

- up: callback which will be called in "up" migration process

- down: callback which will be called in "down" migration process for reverting changes

type MigrationFunc

type MigrationFunc func(ctx context.Context, engine elasticx.Engine) error

MigrationFunc is used to define actions to be performed for a migration.

type Migrations added in v0.0.50

type Migrations []Migration

func (Migrations) Sort added in v0.0.50

func (m Migrations) Sort()

type Migrator

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

Migrate is type for performing migrations in provided database. Database versioned using dedicated collection. Each migration applying ("up" and "down") adds new document to collection. This document consists migration version, migration description and timestamp. Current database version determined as version in latest added document (biggest "_key") from collection mentioned above.

func NewMigrator

func NewMigrator(opts NewMigratorOptions) *Migrator

func (*Migrator) Down

func (m *Migrator) Down(ctx context.Context, targetVersion int) error

Down performs "down" migration to bring back migrations to `version`. If targetVersion<=0 all "down" migrations will be performed. If targetVersion>0, only the down migrations where version>targetVersion will be performed (only if they were applied).

func (*Migrator) SetMigrationsIndex

func (m *Migrator) SetMigrationsIndex(name string)

SetMigrationsIndex replaces name of index for storing migration information. By default it is "migrations".

func (*Migrator) Up

func (m *Migrator) Up(ctx context.Context, targetVersion int) error

Up performs "up" migrations up to the specified targetVersion. If targetVersion<=0 all "up" migrations will be executed (if not executed yet) If targetVersion>0 only migrations where version<=targetVersion will be performed (if not executed yet)

func (*Migrator) Version

func (m *Migrator) Version(ctx context.Context) (migrationVersionInfo, error)

Version returns current engine version and comment.

type NewMigratorOptions added in v0.0.32

type NewMigratorOptions struct {
	Engine     elasticx.Engine
	Package    string
	Migrations Migrations
}

Jump to

Keyboard shortcuts

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