Package: cassandra-migrate
BRANCH CISTATUSmasterCassandra-migrateSimple Cassandra schema migration tool.InstallationRunpip installcassandra-migrate, orpython ./setup.py installReasoningUnlike other available tools, this one:Written in Python for easy installationDoes not requirecqlsh, just the Python driverSupports baselining existing database to given versionsSupports partial advancementSupports locking for concurrent instances using Lightweight TransactionsVerifies stored migrations against configured migrationsStores content, checksum, date and state of every migrationSupports deploying with different keyspace configurations for different environmentsSupports cql and python scripts migrationsConfigurationDatabases are configured through YAML files. For example:keyspace:herbieprofiles:prod:replication:class:SimpleStrategyreplication_factor:3migrations_path:./migrationsWhere themigrationsfolder (relative to the config file). contains.cqlor.pyfiles. The files are loaded in lexical order.The default convention is to name them in the form:v001_my_migration.{cql| py}.
A custom naming scheme can be specified with thenew_migration_nameoption.Note: new_migration_text is deprecated. The specific file type option should be used instead.For example# Date-based migration namesnew_migration_name:"v{date:YYYYMMDDHHmmss}_{desc}"# Default migration namesnew_migration_name:"v{next_version:03d}_{desc}"# Custom initial migration contentnew_migration_text:|/* Cassandra migration for keyspace {keyspace}.Version {next_version} - {date}{full_desc} */# Custom initial migration content for cql scriptsnew_cql_migration_text:|/* Cassandra migration for keyspace {keyspace}.Version {next_version} - {date}{full_desc} */# Custom initial migration content for python scriptsnew_python_migration_text:|# Cassandra migration for keyspace {keyspace}.# Version {next_version} - {date}# {full_desc} */def execute(session, **kwargs):"""Main method for your migration. Do not rename this method.Raise an exception of any kind to abort the migration."""print("Cassandra session: ", session)new_migration_nameis a new-style Python format string, which can use the
following parameters:next_version: Number of the newly generated migration (as anint).desc: filename-clean description of the migration, as specified
by the user.full_desc: unmodified description, possibly containing special characters.date: current date in UTC. Pay attention to the choice of formatting,
otherwise you might include spaces in the file name. The above example should
be a good starting point.keyspace: name of the configured keyspace.The format string shouldnotcontain the .cql or .py extensions, as it they
added automatically.new_migraton_textis handled with the same rules outline above, but defines
the initial content of the migration file, if the type-specific options below
ared not set.new_cql_migraton_textdefines the initial content of CQL migration files.new_python_migraton_textdefines the initial content of Python migration
files.ProfilesProfiles can be defined in the configuration file. They can configure
thereplicationanddurable_writesparameters forCREATE KEYSPACE. A defaultdevprofile is implicitly defined
using a replication factor of 1.UsageCommon parameters:-H HOSTS, --hosts HOSTS
                      Comma-separated list of contact points
-p PORT, --port PORT  Connection port
-u USER, --user USER  Connection username
-P PASSWORD, --password PASSWORD
                      Connection password
-c CONFIG_FILE, --config-file CONFIG_FILE
                      Path to configuration file
-m PROFILE, --profile PROFILE
                      Name of keyspace profile to use
-s SSL_CERT, --ssl-cert SSL_CERT
                      File path of .pem or .crt containing certificate of
                      the cassandra host you are connecting to (or the
                      certificate of the CA that signed the host
                      certificate). If this option is provided, cassandra-
                      migrate will use ssl to connect to the cluster. If
                      this option is not provided, the -k and -t options
                      will be ignored.
-k SSL_CLIENT_PRIVATE_KEY, --ssl-client-private-key SSL_CLIENT_PRIVATE_KEY
                      File path of the .key file containing the private key
                      of the host on which the cassandra-migrate command is
                      run. This option must be used in conjuction with the
                      -t option. This option is ignored unless the -s option
                      is provided.
-t SSL_CLIENT_CERT, --ssl-client-cert SSL_CLIENT_CERT
                      File path of the .crt file containing the public
                      certificate of the host on which the cassandra-migrate
                      command is run. This certificate (or the CA that
                      signed it) must be trusted by the cassandra host that
                      migrations are run against. This option must be used
                      in conjuction with the -k option. This option is
                      ignored unless the -s option is provided.
-y, --assume-yes      Automatically answer "yes" for all questionsmigrateAdvances a database to the latest (or chosen) version of migrations.
Creates the keyspace and migrations table if necessary.Migrate will refuse to run if a previous attempt failed. To override
that after cleaning up any leftovers (as Cassandra has no DDL
transactions), use the--forceoption.Examples:# Migrate to the latest database version using the default configuration file,
# connecting to Cassandra in the local machine.cassandra-migrate-H127.0.0.1migrate# Migrate to version 2 using a specific config file.cassandra-migrate-cmydb.ymlmigrate2# Migrate to a version by name.cassandra-migratemigratev005_my_changes.cql# Force migration after a failurecassandra-migratemigrate2--forceresetReset the database by dropping an existing keyspace, then running a
migration.Examples:# Reset the database to the latest versioncassandra-migratereset# Reset the database to a specifis versioncassandra-migratereset3baselineAdvance an existing database version without actually running the
migrations.Useful for starting to manage a pre-existing database without recreating
it from scratch.Examples:# Baseline the existing database to the latest versioncassandra-migratebaseline# Baseline the existing database to a specific versioncassandra-migratebaseline5statusPrint the current status of the database.Example:cassandra-migratestatusgenerateGenerate a new migration file with the appropriate name and a basic header
template, in the configuredmigrations_path.When running the command interactively, the file will be opened by the default
editor. The newly-generated file name will be printed to stdout.To generate a Python script, specify the--pythonoption.See the configuration section for details on migration naming.Example:cassandra-migrategenerate"My migration description"cassandra-migrategenerate"My migration description"--pythonLicense (MIT)Copyright (C) 2017 Cobli

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.