migrate

package
v2.0.0-...-c0d55de Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

README ¶

🚀 GocqlX Migrations

migrate reads migrations from a flat directory containing CQL files. There is no imposed naming schema. Migration name is file name. The order of migrations is the lexicographical order of file names in the directory. You can inject execution of Go code before processing of a migration file, after processing of a migration file, or between statements in a migration file.

For details see example migration.

Documentation ¶

Overview ¶

Package migrate reads migrations from a flat directory containing CQL files. There is no imposed naming schema. Migration name is file name. The order of migrations is the lexicographical order of file names in the directory. You can inject execution of Go code before processing of a migration file, after processing of a migration file, or between statements in a migration file.

Index ¶

Constants ¶

View Source
const (
	AwaitSchemaAgreementDisabled awaitSchemaAgreement = iota
	AwaitSchemaAgreementBeforeEachFile
	AwaitSchemaAgreementBeforeEachStatement
)

Options for checking schema agreement.

Variables ¶

View Source
var DefaultAwaitSchemaAgreement = AwaitSchemaAgreementDisabled

DefaultAwaitSchemaAgreement controls whether checking for cluster schema agreement is disabled or if it is checked before each file or statement is applied. The default is not checking before each file or statement but only once after every migration has been run.

Functions ¶

func FromFS ¶

func FromFS(ctx context.Context, session gocqlx.Session, f fs.FS) error

FromFS executes new CQL files from a file system abstraction (io/fs.FS). The provided FS has to be a flat directory containing *.cql files.

It supports code based migrations, see Callback and CallbackFunc. Any comment in form `-- CALL <name>;` will trigger an CallComment callback.

func Migrate deprecated

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

Migrate is a wrapper around FromFS. It executes migrations from a directory on disk.

Deprecated: use FromFS instead

Types ¶

type CallbackEvent ¶

type CallbackEvent uint8

CallbackEvent specifies type of the event when calling CallbackFunc.

const (
	BeforeMigration CallbackEvent = iota
	AfterMigration
	CallComment
)

enumeration of CallbackEvents

type CallbackFunc ¶

type CallbackFunc func(ctx context.Context, session gocqlx.Session, ev CallbackEvent, name string) error

CallbackFunc enables execution of arbitrary Go code during migration. If error is returned the migration is aborted. BeforeMigration and AfterMigration are triggered before and after processing of each migration file respectively. CallComment is triggered for each comment in a form `-- CALL <name>;` (note the semicolon).

var Callback CallbackFunc

Callback is means of executing Go code during migrations. Use this variable to register a global callback dispatching function. See CallbackFunc for details.

type CallbackRegister ¶

type CallbackRegister map[nameEvent]CallbackFunc

CallbackRegister allows to register a handlers for an event type and a name. It dispatches calls to the registered handlers. If there is no handler registered for CallComment an error is returned.

func (CallbackRegister) Add ¶

Add registers a callback handler.

func (CallbackRegister) Callback ¶

func (r CallbackRegister) Callback(ctx context.Context, session gocqlx.Session, ev CallbackEvent, name string) error

Callback is CallbackFunc.

func (CallbackRegister) Find ¶

Find returns the registered handler.

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 gocqlx.Session) ([]*Info, error)

List provides a listing of applied migrations.

Jump to

Keyboard shortcuts

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