Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Replicate does not seem to work with Rails 4.2.3 and Ruby 2.2.2 #40

Open
ankuriitk opened this issue Nov 25, 2015 · 4 comments
Open

Replicate does not seem to work with Rails 4.2.3 and Ruby 2.2.2 #40

ankuriitk opened this issue Nov 25, 2015 · 4 comments

Comments

@ankuriitk
Copy link

Hi, Replicate gem looks awesome and seems the right thing for selectively copying data from prod to my devel db. However, either I am not following the steps correctly or replicate does not work with Rails 4.2.3. In either case, will appreciate your help. Here is what I did:

  1. Added gem 'replicate' to my Gemfile
  2. Added a config/replicate/dump.rb file that requires 'config/environment' and added simple code to dump Company.find(16)
  3. Ran the following command on my production DB machine:
    RAILS_ENV=prod replicate -r ./config/environment -d config/replicate/dump.rb > dumped_data

When I do this, I get the following error:
/var/www/fbdash/releases/20151124123929/config/application.rb:47:in <class:Application>': undefined method[]' for nil:NilClass (NoMethodError)
from /var/www/fbdash/releases/20151124123929/config/application.rb:17:in <module:AdIQ>' from /var/www/fbdash/releases/20151124123929/config/application.rb:16:in<top (required)>'
from /var/www/fbdash/releases/20151124123929/config/environment.rb:2:in `require'

My application.rb snippet looks like this:
...
LIne 46: redis_config = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]
Line 47: url_prefix = redis_config['url_prefix']
db = redis_config['cache_db']

I am not sure why it is not picking redis_config as the prod app works just fine.

@ankuriitk
Copy link
Author

Any update on this? @rtomayko can you please help ?

@rtomayko
Copy link
Owner

Hmm, yeah it looks like redis_config is nil. Maybe try RAILS_ENV=production instead of "prod"? This smells like a general environment loading issue.

@ankuriitk
Copy link
Author

Thanks @rtomayko for the quick response. My bad for the typo. After giving RAILS_ENV=production, I get the following error. Do I need to explicitly give dump_replicants for each AR class? I thought replicate gem handles that automatically?

/var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:85:in block in dump': Company must respond to #dump_replicant (NoMethodError) from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:78:ineach'
from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:78:in dump' from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:60:inblock in load_script'
from config/replicate/dump.rb:4:in load_script' from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:61:ininstance_eval'
from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:61:in load_script' from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/bin/replicate:77:inblock in <top (required)>'
from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:28:in block in initialize' from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/emitter.rb:9:ininitialize'
from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/lib/replicate/dumper.rb:26:in initialize' from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/bin/replicate:70:innew'
from /var/www/fbdash/shared/bundle/ruby/2.2.0/gems/replicate-1.5.1/bin/replicate:70:in <top (required)>' from /home/deploy/.rvm/gems/ruby-2.2.2/bin/replicate:23:inload'
from /home/deploy/.rvm/gems/ruby-2.2.2/bin/replicate:23:in <main>' from /home/deploy/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:ineval'
from /home/deploy/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `

'

@u007
Copy link

u007 commented Jan 31, 2016

it requires to declare this method on all models,
so ive added to my base model

def dump_replicant(dumper, opts={})
    fields = attribute_names
    dumper.write self.class, id, fields, self
end

but for some reason, the data being exported and imported without values.
ive many rows without values in most of the fields

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants