Git Product home page Git Product logo

node-cassandra-migration's Introduction

Cassandra Migration

Migrates the schema of Cassandra based on the definition contained within CQL files matching the specified naming convention in the specified directory.

Installation

npm install --save cassandra-migration

Execution

By default the script will look for a file named migrate.json

Run the script

cassandra-migration migrate.json

Config File

The configuration file contains general options at the top level and the cassandra connection configuration. The cassandra section should comply with the the configuration supported by the cassandra-driver module. All other sections provide directives to the tool itself.

The keyspace is required, and must be created outside of the migrations. The schema_version table will be created within this keyspace.

Example config:

{
  "migrationsDir": "cassandra/schema/migrations",
  "quiet": false,
  "cassandra": {
    "contactPoints": [ "cass0", "cass1" ],
    "datacenterName": "datacenter1",
    "useSingleNode": false,
    "keyspace": "data",
    "protocolOptions": {
      "port": 9042
    },
    "socketOptions": {
      "connectTimeout": 15000
    }
  },
  "auth": {
    "username": "foo",
    "password": "bar"
  }
}
  • The auth section of the config is optional.
  • Also the datacenterName is optional but needed when useSingleNode is set to true. If it is configured, the Cassandra client will use WhiteListPolicy and tries to connect only via the first node of contactPoints that you configured. This follows the recommendations of DataStax to only migrate one node at a time and let the cluster replicate the schema updates itself. Otherwise, there is a chance that the cluster breaks.

Migration Files

The migration files should all be reside at the root level of the directory specified by migrationDir in the config file. Each configuration file should follow the format <VERSION>__<TITLE>.cql

Each query statement within the file should be separated by three hyphens: ---

Example:

CREATE TABLE my_keyspace.my_first_table (
  id int PRIMARY KEY,
  name text,
  record_timestamp timestamp
);
---
CREATE TABLE my_keyspace.my_second_table (
  id int PRIMARY KEY,
  description text,
  record_timestamp timestamp
);

Building

cake build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.