<commit_before>Cassandra Migration
========

A migration tool for Apache Cassandra with CQL based on [<NAME>'s Flyway project](https://github.com/flyway/flyway).

## Why not create an extension to an existing popular database migration project (i.e. Flyway)?
Popular database migration tools, such as Flyway and Liquibase are tailored for relational databases with JDBC. This project exists because...
* Cassandra is not a relational database
* Cassandra does not have transactions
* Cassandra currently does not have production-ready JDBC implementation
* It does not make sense to attempt implementing parity with relational database functions like global sequence IDs for Cassandra
* Cassandra's keyspace should be managed outside the migration tool for sysadmins to configure replication factor, etc
* CQL != SQL
* The tool should be tailored to Cassandra, especially from the perspective of its distributed architecture
* I already use Flyway and I do not want to maintain my own version of Flyway with Cassandra hacks

## Requirements
* Cassandra (Tested with version Apache Cassandra 2.1.5)
* JDK (Tested on JDK 7+)
* Pre-populated keyspace

## Migration version table
```
cassandra@cqlsh:cassandra_migration_test> select * from cassandra_migration_version;
 type | version_rank | checksum   | description | execution_time | installed_by | installed_on             | installed_rank | script             | success | version
------+--------------+------------+-------------+----------------+--------------+--------------------------+----------------+--------------------+---------+---------
  CQL |            1 | -868607833 |       First |             98 |    cassandra | 2015-08-24 15:34:15-0400 |              1 |  V1_0_0__First.cql |    True |   1.0.0
  CQL |            2 |  564832622 |      Second |            172 |    cassandra | 2015-08-24 15:34:16-0400 |              2 | V2_0_0__Second.cql |    True |   2.0.0
```

## Supported Migration Script Types
* .cql files
* Java classes

## Interface
### Java API<commit_msg>Migration script examples added<commit_after>Cassandra Migration
========

A migration tool for Apache Cassandra with CQL based on [<NAME>'s Flyway project](https://github.com/flyway/flyway).

## Why not create an extension to an existing popular database migration project (i.e. Flyway)?
Popular database migration tools, such as Flyway and Liquibase are tailored for relational databases with JDBC. This project exists because...
* Cassandra is not a relational database
* Cassandra does not have transactions
* Cassandra currently does not have production-ready JDBC implementation
* It does not make sense to attempt implementing parity with relational database functions like global sequence IDs for Cassandra
* Cassandra's keyspace should be managed outside the migration tool for sysadmins to configure replication factor, etc
* CQL != SQL
* The tool should be tailored to Cassandra, especially from the perspective of its distributed architecture
* I already use Flyway and I do not want to maintain my own version of Flyway with Cassandra hacks

## Requirements
* Cassandra (Tested with version Apache Cassandra 2.1.5)
* JDK (Tested on JDK 7+)
* Pre-populated keyspace

## Migration version table
```
cassandra@cqlsh:cassandra_migration_test> select * from cassandra_migration_version;
 type | version_rank | checksum   | description | execution_time | installed_by | installed_on             | installed_rank | script             | success | version
------+--------------+------------+-------------+----------------+--------------+--------------------------+----------------+--------------------+---------+---------
  CQL |            1 | -868607833 |       First |             98 |    cassandra | 2015-08-24 15:34:15-0400 |              1 |  V1_0_0__First.cql |    True |   1.0.0
  CQL |            2 |  564832622 |      Second |            172 |    cassandra | 2015-08-24 15:34:16-0400 |              2 | V2_0_0__Second.cql |    True |   2.0.0
```

## Supported Migration Script Types
### .cql files
Example:
```
CREATE TABLE test1 (
  space text,
  key text,
  value text,
  PRIMARY KEY (space, key)
) with CLUSTERING ORDER BY (key ASC);

INSERT INTO test1 (space, key, value) VALUES ('foo', 'blah', 'meh');

UPDATE test1 SET value = 'profit!' WHERE space = 'foo' AND key = 'blah';
```

### Java classes
Example:
```
public class V3_0__Third implements JavaMigration {

    @Override
    public void migrate(Session session) throws Exception {
        Insert insert = QueryBuilder.insertInto("test1");
        insert.value("space", "web");
        insert.value("key", "google");
        insert.value("value", "google.com");

        session.execute(insert);
    }
}
```

## Interface
### Java API
{'fraction_non_alphanumeric': 0.14740615773935048, 'fraction_numerical': 0.03458456347532687, 'mean_word_length': 2.5959059893858982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2381159', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1218, 'n_words': 480}