migrator

package module
v0.0.0-...-6a130d5 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 7 Imported by: 0

README

couch-migrator

Couch migrator is a library that provides migration management operations.

Contents

  1. Installation
  2. Usage
    1. Migrations package
    2. Global slice variable example
  3. License

Installation

go get -v github.com/Devoter/couch-migrator

Usage

The following instructions are only recommendations, of course, you can use the library as like as you wish.

Migrations package

To use the library you should create migrations functions. It is intuitive to declare migrations package in your project. All your migrations should be placed in one slice of type []migration.Migration.

Global slice variable example

There is a simple way to declare the migrations slice:

// migrations/migrations.go
package migrations

import "github.com/Devoter/couch-migrator/migration"

// Migrations is a list of all available migrations.
var Migrations = []migration.Migration{}

License

MIT

Documentation

Index

Constants

View Source
const ErrorCommandRequired = Error("Command required")

ErrorCommandRequired means that no command was specified.

View Source
const ErrorInvalidVersionArgumentFormat = Error("Invalid version argument format")

ErrorInvalidVersionArgumentFormat means that the format of an argument named `version` does not correspond to int64.

View Source
const ErrorMigrationsAreNotInitialized = Error("Migrations are not initialized, try to call `init` at first")

ErrorMigrationsAreNotInitialized means that migrations database is empty.

View Source
const ErrorMigrationsDatabaseAlreadyExists = Error("Migrations database already exists")

ErrorMigrationsDatabaseAlreadyExists means that `migrations` database already exists.

View Source
const ErrorNoMigrations = Error("No migrations")

ErrorNoMigrations means that no migrations ware found at the specified path.

View Source
const ErrorSomeMigrationsAreAbsent = Error("Some migrations are absent")

ErrorSomeMigrationsAreAbsent means that some migrations files are absent.

View Source
const ErrorTargetVersionNotFound = Error("Target migration version was not found")

ErrorTargetVersionNotFound means that the target migration version was not found in migrations list.

View Source
const ErrorUnequalCountsOfMigrations = Error("Unequal counts of `up` and `down` migrations")

ErrorUnequalCountsOfMigrations means that the count of `up` migrations is not equal to the count of `down` migrations.

View Source
const ErrorUnexpectedCommand = Error("Unexpected command")

ErrorUnexpectedCommand means that command name is unknown.

View Source
const ErrorVersionNumberRequired = Error("Version number required")

ErrorVersionNumberRequired means that no version number was specified via command line.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error declares constant error type.

func (Error) Error

func (e Error) Error() string

type Migrator

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

Migrator declares MongoDB migrations manager.

func NewMigrator

func NewMigrator(client *kivik.Client, migrations []migration.Migration) *Migrator

NewMigrator returns a new instance of `Migrator`.

func (*Migrator) Down

func (m *Migrator) Down(client *kivik.Client, dbPrefix string) (oldVersion int64, newVersion int64, err error)

Down downgrades database revision to the previous version.

func (*Migrator) Init

func (m *Migrator) Init(client *kivik.Client, dbPrefix string) (oldVersion int64, newVersion int64, err error)

Init creates `migrations` collection if it does not exist and records the initial zero-migration.

func (*Migrator) Reset

func (m *Migrator) Reset(client *kivik.Client, dbPrefix string) (oldVersion int64, newVersion int64, err error)

Reset resets database to the zero-revision.

func (*Migrator) Run

func (m *Migrator) Run(dbPrefix string, args ...string) (oldVersion int64, newVersion int64, err error)

Run interprets commands.

func (*Migrator) SetVersion

func (m *Migrator) SetVersion(client *kivik.Client, dbPrefix string, target int64) (oldVersion int64,
	newVersion int64, err error)

SetVersion forces database revisiton version.

func (*Migrator) Up

func (m *Migrator) Up(client *kivik.Client, dbPrefix string, target int64) (oldVersion int64, newVersion int64, err error)

Up upgrades database revision to the target or next version.

func (*Migrator) Version

func (m *Migrator) Version(client *kivik.Client, dbPrefix string) (oldVersion int64, newVersion int64, err error)

Version returns current database revision version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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