I have a Rails reporting application that will generate reports for other Rails applications. As such I need to import legacy databases, but might also over time, change them. How do I handle migrations with having, and connecting to, x number of databases? I''ve defined the ''other'' databases connections in my classes: class OtherApp < ActiveRecord::Base self.abstract_class = true establish_connection :otherApp1_development # defined in database.yml def initialize self.establish_connection end end Yet when I use: class CreateApplicationExampleOne < OtherApp def self.up # definitions etc end end and then try to migrate, it fails. I hope I''m missing something small here. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jan-03 13:31 UTC
Re: Handling migrations with multiple databases in Rails
On 3 Jan 2011, at 13:18, Sem Ptiri <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a Rails reporting application that will generate reports for > other Rails applications. > > As such I need to import legacy databases, but might also over time, > change them. > > How do I handle migrations with having, and connecting to, x number of > databases? >You''d want to establish_connection on ActiveRecord::Base, since that''s what create_table etc will use. I''m not sure what will happen with your schema_migrations table (which is how it determines what migrations to one), out of the box rails will always look at your primary database for this. You might find it easier to define a rails env for each of these databases and then run migrate for each such environment. Fred> I''ve defined the ''other'' databases connections in my classes: > > class OtherApp < ActiveRecord::Base > self.abstract_class = true > establish_connection :otherApp1_development # defined in database.yml > > def initialize > self.establish_connection > end > end > > Yet when I use: > > class CreateApplicationExampleOne < OtherApp > def self.up > # definitions etc > end > end > > and then try to migrate, it fails. > > I hope I''m missing something small here. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks. It does seem like multiple DBs and migrations do not necessarily play well. Would be interesting to see a recipe for this somewhere. Frederick Cheung wrote in post #972014:> You might find it easier to define a rails env for each of these > databases and then run migrate for each such environment. > > Fred-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.