Skip to content

Instantly share code, notes, and snippets.

@kagemusha
Created December 21, 2011 04:47
Show Gist options
  • Save kagemusha/1504633 to your computer and use it in GitHub Desktop.
Save kagemusha/1504633 to your computer and use it in GitHub Desktop.
Migrate from Mongo to Postgres in Rails 3.1
Tested on: Rails 3.1, Mongoid 2.0.1, pg 0.12.0 gem
Migrate from Mongo to PG
1. remove mongoid gem
2. add pg gem
3. in application.rb re-add ActiveRecord
4. for all models
- inherit from ActiveRecord::Base
- get rid of Mongoid:Document line
- make migrations and put fields there
- redo embedded relats
5. In initializers/devise.rb may need:
require 'devise/orm/active_record'
#active_record should be default but can be problems
6. Invalidate Session if nec by changing secret_token in initializers
- See https://gist.github.com/1504625
- happens b/c session will prolly have Bson which no longer valid
7. Modify any mongoid-specific query, etc. code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment