Registry / database / cassandra-shift

cassandra-shift

JSON →
library0.2.8jsnpmunverified

A Node.js library for forward-only database migrations in Apache Cassandra. Version 0.2.8 is current. Uses ES6 modules; requires Node.js 12+. Provides deterministic, ordered CQL and JavaScript migrations with automatic state tracking in a dedicated table. Designed to embrace Cassandra's no-rollback model. Supports multiple Cassandra clients and includes validation and inspection utilities. Minimal, explicit API.

npm install cassandra-shift
INSTALL
IMPORT
SIG · CASSANDRA-SHIFT
C
cassandra-shift
databasejavascriptv0.2.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CassandraShift
✓ import CassandraShift from 'cassandra-shift'
✗ const CassandraShift = require('cassandra-shift')
Package is ESM-only since v0.2. CommonJS require() will fail.
CassandraShift
✓ import C from 'cassandra-shift'; const shift = new C(clients, options)
✗ import { CassandraShift } from 'cassandra-shift'
The export is a default export, not a named export.

Initializes two Cassandra clients, creates a migration instance with configuration, and applies pending migrations.

import { Client } from 'cassandra-driver'; import CassandraShift from 'cassandra-shift'; const clients = [ new Client({ contactPoints: ['127.0.0.1'], localDataCenter: 'datacenter1' }), new Client({ contactPoints: ['127.0.0.2'], localDataCenter: 'datacenter2' }) ]; await Promise.all(clients.map(c => c.connect())); const shift = new CassandraShift(clients, { keyspace: 'my_keyspace', dir: './migrations', ensureKeyspace: true, useKeyspace: true }); await shift.migrate(); console.log('Migrations applied.');
Debug
Known issues
breakingVersion 0.2 dropped CommonJS support; the package is now ESM-only.
fix
Switch to ES module import syntax (import). Use dynamic import() if needed from CommonJS, but prefer ESM.
affects: >=0.2.0
deprecatedOptions `ensureKeyspace` and `useKeyspace` may be deprecated in future versions; check changelog.
fix
Explicitly create keyspace before migrations if needed.
affects: >=0.2.0
gotchaMigration files are executed in lexicographical order; ensure numeric prefixes with leading zeros (e.g., 001, 002).
fix
Name files with consistent zero-padded numbers, e.g., '001_init.cql', '002_add_column.js'.
affects: >=0.1.0
gotchaJavaScript migrations must export a default async function; named exports will be ignored.
fix
Use `export default async function(clients) { ... }`.
affects: >=0.2.0
breakingClients array must contain at least one client; passing an empty array throws an error.
fix
Always provide an array with one or more Client instances.
affects: >=0.2.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using CommonJS require() on an ESM-only package.
fix
Change `const CassandraShift = require('cassandra-shift')` to `import CassandraShift from 'cassandra-shift'` and ensure your project is set to use ES modules.
Error: Migration file './migrations/002_add_age_column.js' doesn't export a function
The migration file does not export a default async function.
fix
Add `export default async function(clients) { ... }` to the migration file.
TypeError: clients.map is not a function
The clients argument passed to constructor is not an array.
fix
Ensure clients is an array, e.g., `[client1, client2]`.
Upgrade
Version history
0.2.8latest on npm
Audit
Dependencies
cassandra-driverrequiredRequired for interacting with Apache Cassandra; clients must be passed to the constructor.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
cassandra-shift — npm install cassandra-shift · libregistry