資料遷移指令碼

芬奇發表於2014-12-25
 1 classes = %w(Call City Province Tag)
 2 classes.each do |obj_name|
 3   obj = Object.const_get(obj_name)
 4   obj.establish_connection :production
 5   models = obj.all.to_a
 6   obj.establish_connection :development
 7   ActiveRecord::Base.transaction do 
 8     models.each do |model|
 9       obj.create(model.attributes)
10     end
11   end
12 end

 

相關文章