Search code examples
ruby-on-railsrubycassandracqlcequel

rails 4 app with 2 databases: MySQL and Cassandra - where to begin?


Hi have an existing rails 4 app which is using a MySQL database.

I now need to add code that creates dynamically a new table for every object and its attributes.

I decided to use a No SQL solution for this. Initially I wanted to use Mongo DB since I was familair with this. However, my company supports only Cassandra/redis/solr. So I have to pick one of these.

I chose Cassandra but Im not finding any tutorials or examples on how to use it with an existing rails app with a MySQL DB.

I found this ORM for rails-Cassandra but no idea how to make it work with an existing Active record - mysql system.

Any ideas would be very appreciated.

Apologize this post has no code. But I couldnt find any answers for this issue on SO so please excuse if any mistakes.

thanks


Solution

  • ActiveRecord and Cequel will be independent.

    As shown in their docs you extend a model's functionality by including the Cequel::Record module.

    include Cequel::Record
    

    In order to use it in rails you (obviously) need to add the proper gem in your Gemfile

    gem 'cequel'
    

    and create the configuration for the project

    bundle exec rake cequel:keyspace:create
    

    After that, you will have a config/cequel.yml from where you will define your settings (as you did in config/database.yml for your MySQL)

    MySQL models will still use the ActiveRecord

    class Foo < ActiveRecord::Base
    ...
    end
    

    while Cassandra ones will use the Cequel

    class Bar
      include Cequel::Record
      ...
    end