#RoR NoSQL Migrations: Part 3

Here is how a #nosql migration for #elasticsearch might look using the rake task we built up previously in part 1 and part 2. In this case, we are creating a new mapping and saving all our SQL models which have been configured to update their ES indices when the underlying SQL data is saved.

  $es.indices.create  index: 'items',
    body: {
      mappings: {
        item: {
          _id: { store: true },
          properties: {                            
            name: { type: 'string' }

  Item.all.each {|i|
  abort("Migration failed.")

Notice the begin – rescue block, where on errors we write out the failure “Migration failed” to the STDERR stream which will cause the wrapping system command in our rake task to be false. We could potentially view the STDERR stream and see the details of that failure with any detail we choose to include in the abort call.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s