cqlmigrate

package module
v0.0.0-...-cc6b246 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

README

cqlmigrate

A Cassandra CQL schema migration library for Golang. With this library, you can auto-perform updates to your Cassandra keyspaces without a separate deployment step.

package main

import (
	"github.com/gocql/gocql"
  "github.com/robzienert/cqlmigrate"
)

var migrations = []migration.Spec{
  {
    Name: "2016-01-01-initial_release",
    Data: `
    CREATE TABLE foo (
      my_key varchar,
      my_field varchar
      PRIMARY KEY(my_key)
    );
    `,
  },
}

func main() {
  session, _ := gocql.NewCluster("127.0.0.1").CreateSession()
  
  conf := cqlmigrate.Config{
    Session: session,
    Keyspace: "my_keyspace",
  }
  
  if err := cqlmigrate.New(conf).Run(migrations); err != nil {
    panic(err)
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Session  *gocql.Session
	Keyspace string
	Override bool
}

Config defines the configurations for performing a migration.

Session is the gocql session to run the migrations with.

Keyspace is which Cassandra keyspace the migrations will be run against.

Override can be set to override any previous migrations that may not match the original checksum. By default, this is disabled - use this flag with caution!

type Runner

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

Runner performs the CQL migrations.

func New

func New(conf *Config) *Runner

New creates a new migration Runner

func (*Runner) Run

func (r *Runner) Run(migrations []Spec) (bool, error)

Run performs all of the given migrations. The return value of this function consists of whether or migrations were successfully run, and the second if any errors were encountered.

type Spec

type Spec struct {
	Name string
	Data string
}

Spec defines a single migration step.

Name must be unique, and should be human readable and meaningful.

Data is the CQL schema definition for the migration.

Jump to

Keyboard shortcuts

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