ocean-dynamo

This is the OceanDynamo ruby gem, implementing a highly scalable Amazon DynamoDB near drop-in replacement for ActiveRecord.

OceanDynamo requires Ruby 2.0 and Ruby on Rails 4.0.0 or later.

<img src=“https://badge.fury.io/rb/ocean-dynamo.png” alt=“Gem Version” />

Features

As one important use case for OceanDynamo is to facilitate the conversion of SQL based ActiveRecord models to DynamoDB based models, it is important that the syntax and semantics of OceanDynamo’s operations are as close as possible to those of ActiveRecord. This means that all callbacks should be available, before, around and after, and that they should be called in the same order as in ActiveRecord. OceanDynamo follows this pattern closely and is of course based on ActiveModel.

The attribute and persistence layer of OceanDynamo is modeled on that of ActiveRecord: there’s save, save!, create, update, update!, update_attribute and all the other methods you’re used to. The design goal is always to implement as much as possible of the ActiveRecord interface, without sacrificing scalability. This makes the task of switching from SQL to no-SQL much easier.

Due to its similarity to ActiveRecord, OceanDynamo works with FactoryGirl. Furthermore, future versions will keep track of and delete instances after tests.

OceanDynamo will use secondary indices to retrieve related table items, which means it will scale without limits. (NB: this is a pre-release which as yet doesn’t implement relations, but they are underway.)

Documentation

See also Ocean, a Rails framework for creating highly scalable SOAs in the cloud, in which OceanDynamo is used as a central component:

Running the specs

To run the specs for the OceanDynamo gem, you must first install the bundle. It will download a gem called fake_dynamo, which runs a local, in-memory functional clone of Amazon DynamoDB. We use fake_dynamo during development and testing.

First of all, copy the AWS configuration file from the template:

cp spec/dummy/config/aws.yml.example spec/dummy/config/aws.yml

NB: aws.yml is excluded from source control. This allows you to enter your AWS credentials safely. Note that aws.yml.example is under source control: don’t edit it.

Make sure your have version 0.1.3 of the fake_dynamo gem. It implements the 2011-12-05 version of the DynamoDB API. We’re not yet using the 2012-08-10 version, as the aws-sdk ruby gem doesn’t fully support it. We’ll make the change as soon as aws-sdk is updated. Reportedly, it’s in the works.

Next, start fake_dynamo:

fake_dynamo --port 4567

If this returns errors, make sure that /usr/local/var/fake_dynamo exists and is writable:

sudo mkdir -p /usr/local/var/fake_dynamo
sudo chown peterb:staff /usr/local/var/fake_dynamo

When fake_dynamo runs normally, open another window and issue the following command:

curl -X DELETE http://localhost:4567

This will reset the fake_dynamo database. It’s not a required operation when starting fake_dynamo; we’re just using it here as a test that the installation works. It will be issued automatically as part of the test suite, so don’t expect test data to survive between runs.

With fake_dynamo running, you should now be able to do

rspec

All tests should pass.

Rails console

The Rails console is available from the built-in dummy application:

cd spec/dummy
rails console

You may need to initialise the table connection (for each table):

CloudModel.establish_db_connection

This will, amongst other things, also create the CloudModel table if it doesn’t already exist. On Amazon, this will take a little while. With fake_dynamo, it’s practically instant.

When you leave the console, you must navigate back to the top directory (cd ../..) in order to be able to run RSpec again.