Hi, I''m trying to connect to a Mysql database using MysqlAdapter, so I can migrate some data from a system that is being replaced by a Rails application. This requires having an open connection to two different databases, one of which I will query directly, and the other being used for the new application''s models. I started with ActiveRecord::Base.establish_connection to connect to the previous apps database, but when I do that it changes the models in my new application to attempt to use that database as well, making it impossible to save the newly migrated data. Can somebody give an example of how to create a standalone connection, which isn''t being tracked by ActiveRecord? I''ve tried MysqlAdapter.new, but I have no idea what the parameters are meant to be (despite several hours of running in circles through ActiveRecord''s internals), so I havn''t been able to open a connection yet. Thanks, Jon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Just in case anyone comes across this, I ended up solving it by establishing a new connection for each ActiveRecord model as it''s loaded - it''s a bit of a hack, but it''s got my code running, so I''m happy for now. class ActiveRecord::Base def self.inherited(subclass) super(subclass) subclass.establish_connection(RAILS_ENV) end end I''m not sure that I need the call to super there, but I''m leaving it in just for safety. Jon On Feb 21, 6:46 pm, Jon Wood <j...-3X2+zLsKDO3k1uMJSBkQmQ@public.gmane.org> wrote:> Hi, > > I''m trying to connect to a Mysql database using MysqlAdapter, so I can > migrate some data from a system that is being replaced by a Rails > application. This requires having an open connection to two different > databases, one of which I will query directly, and the other being > used for the new application''s models. > > I started with ActiveRecord::Base.establish_connection to connect to > the previous apps database, but when I do that it changes the models > in my new application to attempt to use that database as well, making > it impossible to save the newly migrated data. > > Can somebody give an example of how to create a standalone connection, > which isn''t being tracked by ActiveRecord? I''ve tried > MysqlAdapter.new, but I have no idea what the parameters are meant to > be (despite several hours of running in circles through ActiveRecord''s > internals), so I havn''t been able to open a connection yet. > > Thanks, > > Jon--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What I did to migrate data from MS Access to SQL Server. I just created a raw connection to Access and used DBI/DBD calls to pull back data. There wasn''t much point in even trying to use ActiveRecord because the Access DB didn''t conform to any model objects. To put data into SQL Server, I used my ActiveRecord models. So, pulling the data from Access, I would use it to create new models that I would save. If you''re thinking "Gee, that''s inefficient," wrap the creation of model objects in transactions. Also, unless you''re migrating data on a regular basis, you should only need to run this migration in the process of developing your application (I did the data migration code inside a Rails migration). Another advantage of using the combination of raw DBI/DBD calls from the source database and Models for the destination database is the case where 1 row in the source table maps to multiple objects in the destination database. paul On Thu, 2008-02-21 at 10:46 -0800, Jon Wood wrote:> Hi, > > I''m trying to connect to a Mysql database using MysqlAdapter, so I can > migrate some data from a system that is being replaced by a Rails > application. This requires having an open connection to two different > databases, one of which I will query directly, and the other being > used for the new application''s models. > > I started with ActiveRecord::Base.establish_connection to connect to > the previous apps database, but when I do that it changes the models > in my new application to attempt to use that database as well, making > it impossible to save the newly migrated data. > > Can somebody give an example of how to create a standalone connection, > which isn''t being tracked by ActiveRecord? I''ve tried > MysqlAdapter.new, but I have no idea what the parameters are meant to > be (despite several hours of running in circles through ActiveRecord''s > internals), so I havn''t been able to open a connection yet. > > Thanks, > > Jon > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---