Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating from mongodb to postgresql in rails

I'm using MongoDB with mongo_mapper gem in Rails and project is big enough. Is there any way I can migrate data from Mongoid to Postgresql?

like image 575
Aydar Omurbekov Avatar asked Sep 13 '13 16:09

Aydar Omurbekov


1 Answers

You should look into some of the automated migration/replication tools like MoSQL: https://stripe.com/blog/announcing-mosql

One risky strategy for this migration would be to convert your codebase to using postgres and all of your models, put your site into maintenance mode, migrate your databases, deploy the new code, and bring it back up. However, this requires significant downtime and development risk of bugs or data loss.

A safer, but much more involved strategy would be to setup automatic migration of data to a new database to sync up your databases. Then, every action in the application writes to both databases. After each transaction, you verify the data is in sync between both databases and read from Mongo. This allows you to fix errors as you find them and highlight any inconsistencies. Once you are no longer finding discrepancies, you can turn off writing to mongo and retire that database, remove the mongo models/code, and move on.

like image 63
Winfield Avatar answered Sep 22 '22 17:09

Winfield