migrate

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 16 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 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, n int) error

Down performs "down" migration to oldest available version. If n<=0 all "down" migrations with older version will be performed. If n>0 only n migrations with older version will be performed.

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, n int) error

Up performs "up" migrations to latest available version. If n<=0 all "up" migrations with newer versions will be performed. If n>0 only n migrations with newer version will be performed.

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 []Migration
}

Jump to

Keyboard shortcuts

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