replicate
replicate copied to clipboard
Replicate does not seem to work with Rails 4.2.3 and Ruby 2.2.2
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:
- Added gem 'replicate' to my Gemfile
- Added a config/replicate/dump.rb file that requires 'config/environment' and added simple code to dump Company.find(16)
- 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.
Any update on this? @rtomayko can you please help ?
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.
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:in
each'
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:in
block 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:in
instance_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:in
block 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:in
initialize'
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:in
new'
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:in
load'
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:in
eval'
from /home/deploy/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `
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