migrate

package
v1.5.1-0...-9d7d344 Latest Latest
Warning

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

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

README

GoCQLX Migrations

Package migrate provides simple and flexible CQL 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.

Features

  • Each CQL statement will run once
  • Go code migrations using callbacks

Example

package main

import (
    "context"

    "github.com/scylladb/gocqlx/migrate"
)

const dir = "./cql" 

func main() {
    session := CreateSession()
    defer session.Close()

    ctx := context.Background()
    if err := migrate.Migrate(ctx, session, dir); err != nil {
        panic(err)
    }
}

Documentation

Overview

Package migrate provides simple and flexible CLQ 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

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 Migrate

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

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

Types

type CallbackEvent

type CallbackEvent uint8

CallbackEvent specifies type of the event when calling CallbackFunc.

const (
	BeforeMigration CallbackEvent = iota
	AfterMigration
)

enumeration of CallbackEvents

type CallbackFunc

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

CallbackFunc enables interrupting the migration process and executing code while migrating. If error is returned the migration is aborted.

var Callback CallbackFunc

Callback is called before and after each migration. See CallbackFunc for details.

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) ([]*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