migrate

package
v0.0.0-...-11bee42 Latest Latest
Warning

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

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

Documentation

Overview

Package migrate provides simple and flexible ScyllaDB and Apache Cassandra® migrations. Migrations can be read from a flat directory containing cql files. There is no imposed naming schema, migration name is file name and the migrations are processed in lexicographical order. Caller provides a gocql.Session, the session must use a desired keyspace as migrate would try to create migrations table.

Index

Constants

This section is empty.

Variables

View Source
var ErrMigratorTableMissing = errors.New("the migrator table object cannot be nil")

ErrMigratorTableMissing is returned if the migrator table object is nil.

View Source
var ErrNoCQLStatement = errors.New("no CQL statement found")

ErrNoCQLStatement is returned when trying to execute a non cql statement i.e. "This is not cql"

View Source
var ErrNoMigrationsFound = errors.New("no migrations were found")

ErrNoMigrationsFound is returned if the directory provided doesn't contain any migrations.

View Source
var ErrNoSessionProvided = errors.New("no session provided to the Cassandra migrator")

ErrNoSessionProvided is returned when trying to create a Cassandra migrator without a session.

Functions

func Migrate

func Migrate(ctx context.Context, session *gocql.Session, dir string) error

Migrate reads the cql files from a directory and applies required migrations.

func SetMigratorTable

func SetMigratorTable(mt MigratorTable)

SetMigratorTable sets the default migrator table instance to use when calling List or Migrate.

Types

type Info

type Info struct {
	Name      string
	Checksum  string
	Done      int
	StartTime time.Time
	EndTime   time.Time
}

Info contains information on migration applied on a database.

func List

func List(ctx context.Context, session *gocql.Session) (v []*Info, err error)

List provides a listing of applied migrations.

type Migrator

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

Migrator provides the migration facility.

func NewMigratorWithFileSystem

func NewMigratorWithFileSystem(fs http.FileSystem, mt MigratorTable) (*Migrator, error)

NewMigratorWithFileSystem returns a migrator reading the migrations from an http.FileSystem.

func (*Migrator) Migrate

func (m *Migrator) Migrate(ctx context.Context) (err error)

Migrate executes the migrations found in the source.

type MigratorTable

type MigratorTable interface {
	List(ctx context.Context) ([]*Info, error)
	Execute(ctx context.Context, stmt string, info Info) error
}

MigratorTable interface operates on the gocqlx_migrate table. Tests can substitute a mock implementation.

func NewCassandraSessionMigrator

func NewCassandraSessionMigrator(session *gocql.Session) (MigratorTable, error)

NewCassandraSessionMigrator creates a migrator that persists into and reads from a Cassandra database.

Jump to

Keyboard shortcuts

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