greetings, I''m wondering if anyone else has faces the task of migrating multiple databases? How can one do this is an automated fashion? Currently I''m running usual "rake db:migrate" from cmd, where I''ll manually edit the database.yml :database line to indicate the current DB. This is done is a sequential fashion. While this is fine for working out the migrations, it''s going to be real tedious for migrating the 50+ production databases. Thus I''d like to come up with a ruby script that will run the migration for each DB automatically. Two issues I see... 1. how does one run migrations from ruby? is it a `/path_to_app/rake db:migrate`, generally I like to avoid cmd line executions in scripts 2. how does one programmatically reset the migration connection? I know I can do a "model_obj.establish_connection" for ActiveRecord, but I don''t see anything similar for migration. Having these resolved, I envision something like... database_list.each{|db| migration.connection(db) migration.run } Thank You, andy koch --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Fitzgibbons
2007-Jul-17 19:36 UTC
Re: migrations via script || migrate multiple DB''s
HI Andy, I believe you need to be looking at Capistrano. Depending upon your situation. And, if I may ask, what kind of app is using 50+ identical databases? -- Peter Fitzgibbons ------------------------------ iPhone -- "IT"-ness. hrefhttp://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object ------------------------------ On 7/17/07, Andy Koch <andy.koch-sBIqA0PYact54TAoqtyWWQ@public.gmane.org> wrote:> > > greetings, > > I''m wondering if anyone else has faces the task of migrating multiple > databases? How can one do this is an automated fashion? > > Currently I''m running usual "rake db:migrate" from cmd, where I''ll > manually edit the database.yml :database line to indicate the current > DB. This is done is a sequential fashion. While this is fine for > working out the migrations, it''s going to be real tedious for migrating > the 50+ production databases. > > Thus I''d like to come up with a ruby script that will run the migration > for each DB automatically. > > Two issues I see... > 1. how does one run migrations from ruby? is it a `/path_to_app/rake > db:migrate`, generally I like to avoid cmd line executions in scripts > > 2. how does one programmatically reset the migration connection? I know > I can do a "model_obj.establish_connection" for ActiveRecord, but I > don''t see anything similar for migration. > > > Having these resolved, I envision something like... > > > database_list.each{|db| > migration.connection(db) > migration.run > } > > > > Thank You, > > andy koch > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Fitzgibbons schrieb:> HI Andy, > > I believe you need to be looking at Capistrano. Depending upon your > situation. > > And, if I may ask, what kind of app is using 50+ identical databases? > > -- > Peter Fitzgibbonsah, I was thinking of Cap, but I''m fairly hackish with it. I''ll see where that leads me. what kind of app? sure you may ask, it''s an inherited PHP app that runs Firebird. the app manages text strings for desktop apps where each DB is a different branch I didn''t design it, I inherited it, and now I''m rail-ifying it. /ak --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Fitzgibbons
2007-Jul-19 15:43 UTC
Re: migrations via script || migrate multiple DB''s
Without knowing more detail, it sounds like your design could use some refactoring-love along the way. Maybe a couple habtm tables with strings/context relationships? Good luck! On 7/17/07, Andy Koch <andy.koch-sBIqA0PYact54TAoqtyWWQ@public.gmane.org> wrote:> > > Peter Fitzgibbons schrieb: > > HI Andy, > > > > I believe you need to be looking at Capistrano. Depending upon your > > situation. > > > > And, if I may ask, what kind of app is using 50+ identical databases? > > > > -- > > Peter Fitzgibbons > > ah, I was thinking of Cap, but I''m fairly hackish with it. I''ll see > where that leads me. > > what kind of app? sure you may ask, it''s an inherited PHP app that runs > Firebird. the app manages text strings for desktop apps where each DB > is a different branch > > I didn''t design it, I inherited it, and now I''m rail-ifying it. > > /ak > > > > >-- Peter Fitzgibbons ------------------------------ iPhone -- "IT"-ness. hrefhttp://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object ------------------------------ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you have multiple databases with the same schema, you might use something like: databases.each do |database| ActiveRecord::Base.establish_connection :adapter => "adapter", :host => "host", :username => "username", :password => "password", :database => database ActiveRecord::Migrator.migrate("db/migrate/") end I made a db:migrate_all rake task http://pastie.caboo.se/113856 (which I saved in lib/tasks/migrate_all.rake) Just need to play with better sql config, probably read from database.yml, but it works fine for me having one rails app, kind of CMS, connecting to database dependently on request.host in application controller, so each site has its own db and data directory. I had to do this because I have mongrel_cluster with apache mod_proxy_balancer, and I cannot afford to run cluster for each site, so I need one rails app with one scalable mongrel_cluster and a lot of sites sharing it. Got hint with this from guy with nick pythonic on #rubyonrails-0M+Kt+TIN6Xk1uMJSBkQmQ@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---