{"id":15430724,"url":"https://github.com/hsgubert/cassandra_migrations","last_synced_at":"2025-10-26T13:08:15.287Z","repository":{"id":7738350,"uuid":"9105044","full_name":"hsgubert/cassandra_migrations","owner":"hsgubert","description":"Cassandra Migrations is a Cassandra database schema migration library for Rails applications.","archived":false,"fork":false,"pushed_at":"2022-10-27T08:03:44.000Z","size":206,"stargazers_count":45,"open_issues_count":12,"forks_count":43,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T05:08:48.424Z","etag":null,"topics":["cassandra-database","cassandra-migration","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hsgubert.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-29T19:23:56.000Z","updated_at":"2022-11-02T19:04:54.000Z","dependencies_parsed_at":"2022-08-26T07:10:49.816Z","dependency_job_id":null,"html_url":"https://github.com/hsgubert/cassandra_migrations","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsgubert%2Fcassandra_migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsgubert%2Fcassandra_migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsgubert%2Fcassandra_migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsgubert%2Fcassandra_migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hsgubert","download_url":"https://codeload.github.com/hsgubert/cassandra_migrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008629,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra-database","cassandra-migration","rails","ruby"],"created_at":"2024-10-01T18:18:29.336Z","updated_at":"2025-10-26T13:08:15.225Z","avatar_url":"https://github.com/hsgubert.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cassandra Migrations\n[![Gem Version](https://badge.fury.io/rb/cassandra_migrations.png)](http://badge.fury.io/rb/cassandra_migrations)\n[![Code Climate](https://codeclimate.com/github/hsgubert/cassandra_migrations.png)](https://codeclimate.com/github/hsgubert/cassandra_migrations)\n\n## Description\nCassandra Migrations is a Cassandra database schema migration library for Rails applications.\n\nThis gem provides:\n  * Multi-environment database configuration\n  * Versioned CQL schema migration management\n  * A schema modification DSL for simplified migration code\n  * Rake tasks for database schema management\n  * Support for forked processes\n\nUse Cassandra in an organized and familiar way, without changing how you work with your ActiveRecord relational database schema.\n\n## Requirements\n\n- Cassandra \u003e= 1.2, using the native transport protocol\n- Ruby \u003e= 1.9\n- Rails \u003e= 3.2\n\n## Installation\n\n```ruby\ngem install cassandra_migrations\n```\n\nor, with bundler, add the following to your gemfile:\n\n```\ngem 'cassandra_migrations'\n```\n\n## Configuration\n\nSimilar to how `config/database.yml` stores your relational databse configuration, `config/cassandra.yml` stores your cassandra database configuration.\n\n```\nrails g cassandra_configuration\n```\n\nThis will create the `config/cassandra.yml` with default settings. Configure the database names for each of your environments.\n\n```yml\ndevelopment:\n  hosts:\n    - 127.0.0.1\n  port: 9042\n  keyspace: my_keyspace_dev\n  replication:\n    class: SimpleStrategy\n    replication_factor: 1\n```\n\nThese are the minimum options to get started, for advanced configuration, read about [Database Configuration Options](wiki/Database Configuration Options).\n\nAssuming your Cassandra database is running, you may now create your keyspace:\n\n```bash\nrake cassandra:create\n```\n\n## Migrations\n\nSimilar to how `db/migrate/` stores your relational databse schema migration files, `db/cassandra_migrate/` stores your Cassandra schema migration files.\n\n``` bash\nrails g cassandra_migration create_posts\n```\n\nThis will create a versioned migration in `db/cassandra_migrate/`, with familiar `up` and `down` methods that will be executed when applying or rolling back a migration, respectively.\n\n```ruby\nclass CreatePosts \u003c CassandraMigrations::Migration\n  def up\n  end\n\n  def down\n  end\nend\n```\nYou may call `execute` from these methods to execute CQL statements to your configured keyspace.\n\n### Cassandra Migrations DSL\n\nFor increased readability and ease of use, there is also a familiar DSL available from the migration methods.\n\n```ruby\nclass CreatePosts \u003c CassandraMigrations::Migration\n  def up\n    create_table :posts,\n                 partition_keys: [:id, :created_month],\n                 primary_keys:   [:created_at] do |t|\n      t.integer   :id\n      t.string    :created_month\n      t.timestamp :created_at\n      t.string    :title\n      t.string    :category\n      t.set       :tags, type: :float\n      t.map       :my_map, key_type: :uuid, value_type: :float\n      t.text      :content\n    end\n\n    create_index :posts, :category, name: 'posts_by_category'\n  end\n\n  def down\n    drop_index 'posts_by_category'\n    drop_table :posts\n  end\nend\n```\n\nUse the following type methods for fields:\n\n* `text`\n* `integer`\n* `decimal`\n* `float`\n* `double`\n* `boolean`\n* `uuid`\n* `timeuuid`\n* `inet`\n* `timestamp`\n* `datetime`\n* `binary`\n* `list` (with `type` option)\n* `set` (with `type` option)\n* `map` (with `key_type` and `value_type` options)\n\nFor more details on the DSL's types, advanced table options, keyspace manipulation, or other schema statment methods, read about the [Migration DSL](wiki/Migration DSL).\n\n### Rake Tasks\n\nThere are a collection of familiar rake tasks to help you manage your cassandra databases.\n\n  * **`rake cassandra:create`** Creates the configured keyspace in `config/cassandra.yml`.\n  * **`rake cassandra:drop`** Drops the configured keyspace in `config/cassandra.yml`.\n  * **`rake cassandra:migrate`** Runs migrations that have not run yet.\n  * **`rake cassandra:rollback`** Rolls back the latest migration that has been applied.\n  * **`rake cassandra:migrate:reset`**  Runs `cassandra:drop`, `cassandra:create` and `cassandra:migrate`.\n\nEach rake task will be run against the database that is configured for the current environment (via `RAILS_ENV`).\n\n```\nrake cassandra:migrate\n```\n\n```bash\n\n== CreatePosts: migrating =====================================================\n  create_table(posts)\n  -\u003e CREATE TABLE posts (id int, created_month varchar, created_at timestamp, title varchar, category varchar, content text, PRIMARY KEY((id, created_month), created_at))\n  create_index(posts)\n  -\u003e CREATE INDEX posts_by_category ON posts (category)\n== CreatePosts: migrated (0.3448s) ============================================\n\nMigrated 1 version(s) up.\n```\n\nFor more details on available rake tasks and options, read about [Rake Tasks](wiki/Rake Tasks).\n\n## Query Helpers\n\nWhen a migration requires working with data, not just schema, one option is using the Cassandra Migration query classes.\n\n```ruby\nCassandraMigrations::Cassandra.select(:posts)\n```\n\n```ruby\nnew posts = CassandraMigrations::Cassandra.select(:posts,\n  projection: 'title, created_at',\n  selection: 'id \u003e 1234',\n  order_by: 'created_at DESC',\n  limit: 10\n)\n\nnew_posts.each do |post|\n  CassandraMigrations::Cassandra.update!(:posts,\n    \"id = #{post['id']}\",\n    {tags: ['new']},\n    {operations: {tags: :+}})\nend\n```\n\nFor more details, options, and examples, read about the [Query Helpers](wiki/Query Helpers).\n\n\n## Deployment\n\n### Passenger\n\nCassandra Migrations has built-in support for Passenger's forked process model (e.g. smart spawning).\n\n### Other forked web servers (Puma, Unicorn, etc.)\n\nEach fork should contain its own session to avoid deadlock and other issues. Restart the connection after the process has forked.\n\n```\n# config/puma.rb\non_worker_boot do\n  # re-establish the connection in this process fork\n  CassandraMigrations::Cassandra.restart\nend\n```\n\n### Capistrano\n\nTo add cassandra database creation and migrations steps to your Capistrano recipe, add the following line to you deploy.rb:\n`require 'cassandra_migrations/capistrano'`\n\n\n## Development\n\nTo run the test suite:\n\n`bundle install`\n\n`rake`\n\nAdditionally, this project aims for compatiblity with Rails 3.2 and above. For that, we use the `appraisal` [gem](https://github.com/thoughtbot/appraisal). If you make changes, run our test suite against all supported version of Rails like so:\n\n`appraisal install`\n\n`appraisal rake`\n\n## Contributors\n* Henrique Gubert - @hsgubert\n* Brian Sam-Bodden - @bsbodden\n* Sid Tantia - @sstgithub\n* [and more...](https://github.com/hsgubert/cassandra_migrations/graphs/contributors)\n\n## Acknowledgements\n\nThis gem is built upon the official [Ruby Driver for Apache Cassandra](https://github.com/datastax/ruby-driver) by DataStax.\nWhich supersedes the [cql-rb](https://github.com/iconara/cql-rb) gem (thank you Theo for doing an awesome job).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsgubert%2Fcassandra_migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsgubert%2Fcassandra_migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsgubert%2Fcassandra_migrations/lists"}