Hey all. I''m trying to export my app''s data from mysql to postgres in advance of a database switch. I''ve tried this: task(:export => :environment) do @users=User.find(:all) ActiveRecord::Base.establish_connection(:pg) for user in @users user.save_with_validation(perform_validation = false) end ActiveRecord::Base.establish_connection(:development) end However, nothing''s happening -- no activity in the pg environment log, no records added. I''ve also tried exporting as yaml and then importing, using Tobias Lutke''s approach (http://blog.leetsoft.com/files/code/backup.rake) However, the import bombs here: myFile=YAML.load_file("#{tbl}.yml") because of some unexpected quote marks in some of the content. Any help getting either of these approaches to work would be hugely appreciated.
On Sat, May 16, 2009 at 9:11 AM, magic_hat <magic_hat60622-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Hey all. I''m trying to export my app''s data from mysql to postgres in > advance of a database switch.Check out the yaml_db plugin: <http://agilewebdevelopment.com/plugins/yamldb> FWIW, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
On Saturday 16 May 2009, magic_hat wrote:> Hey all. I''m trying to export my app''s data from mysql to postgres in > advance of a database switch.Try exporting and importing YAML first. If that doesn''t work, you may have better luck with mysqldump + mysql2pgsql[*] + psql. Michael [*] http://pgfoundry.org/projects/mysql2pgsql/ -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/
Hassan, the yaml_db plugin looked promising, but it''s bombing because of unbalanced quotes in some of the content, much like the code from Tobias that I posted. On May 16, 12:06 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, May 16, 2009 at 9:11 AM, magic_hat <magic_hat60...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > Hey all. I''m trying to export my app''s data from mysql to postgres in > > advance of a database switch. > > Check out the yaml_db plugin: > <http://agilewebdevelopment.com/plugins/yamldb> > > FWIW, > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Michael, the perl script looks great, but I''m getting a segmentation fault error when I run, perhaps because some of the content involves long news articles. On May 16, 9:29 pm, magic_hat <magic_hat60...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hassan, > > the yaml_db plugin looked promising, but it''s bombing because of > unbalanced quotes in some of the content, much like the code from > Tobias that I posted. > > On May 16, 12:06 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Sat, May 16, 2009 at 9:11 AM, magic_hat <magic_hat60...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > Hey all. I''m trying to export my app''s data from mysql to postgres in > > > advance of a database switch. > > > Check out the yaml_db plugin: > > <http://agilewebdevelopment.com/plugins/yamldb> > > > FWIW, > > -- > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
If it just the unbalanced quotes that are causing the problem you could possibly first convert all the quotes to some escape sequence then transfer the database, and then convert the escape sequences back again. Colin 2009/5/17 magic_hat <magic_hat60622-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>> > Michael, > > the perl script looks great, but I''m getting a segmentation fault > error when I run, perhaps because some of the content involves long > news articles. > > On May 16, 9:29 pm, magic_hat <magic_hat60...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > Hassan, > > > > the yaml_db plugin looked promising, but it''s bombing because of > > unbalanced quotes in some of the content, much like the code from > > Tobias that I posted. > > > > On May 16, 12:06 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > > On Sat, May 16, 2009 at 9:11 AM, magic_hat <magic_hat60...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > Hey all. I''m trying to export my app''s data from mysql to postgres in > > > > advance of a database switch. > > > > > Check out the yaml_db plugin: > > > <http://agilewebdevelopment.com/plugins/yamldb> > > > > > FWIW, > > > -- > > > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
magic_hat wrote:> Hey all. I''m trying to export my app''s data from mysql to postgres in > advance of a database switch. > > I''ve tried this: > > task(:export => :environment) do > @users=User.find(:all) > ActiveRecord::Base.establish_connection(:pg) > for user in @users > user.save_with_validation(perform_validation = false) > end > ActiveRecord::Base.establish_connection(:development) > end > > However, nothing''s happening -- no activity in the pg environment log, > no records added.Did you look at this plugin? http://agilewebdevelopment.com/plugins/manage_fixtures [%] rake db:fixtures:export_all RAILS_ENV=development [%] rake db:fixtures:load When loading specify your new database, RAILS_ENV=new_development or other. Stephan> I''ve also tried exporting as yaml and then importing, using Tobias > Lutke''s approach (http://blog.leetsoft.com/files/code/backup.rake) > > However, the import bombs here: > myFile=YAML.load_file("#{tbl}.yml") > because of some unexpected quote marks in some of the content. > > Any help getting either of these approaches to work would be hugely > appreciated.-- Posted via http://www.ruby-forum.com/.
On Sat, May 16, 2009 at 7:29 PM, magic_hat <magic_hat60622-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> the yaml_db plugin looked promising, but it''s bombing because of > unbalanced quotes in some of the contentouch. Can you post the stack trace and an example data row that''s causing the problem? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> Hey all. I''m trying to export my app''s data from mysql to postgres in > advance of a database switch. > > I''ve tried this: > > task(:export => :environment) do > @users=User.find(:all) > ActiveRecord::Base.establish_connection(:pg) > for user in @users > user.save_with_validation(perform_validation = false) > end > ActiveRecord::Base.establish_connection(:development) > end > > However, nothing''s happening -- no activity in the pg environment log, > no records added. > > I''ve also tried exporting as yaml and then importing, using Tobias > Lutke''s approach (http://blog.leetsoft.com/files/code/backup.rake) > > However, the import bombs here: > myFile=YAML.load_file("#{tbl}.yml") > because of some unexpected quote marks in some of the content. > > Any help getting either of these approaches to work would be hugely > appreciated.Taps (http://adam.blog.heroku.com/past/2009/2/11/ taps_for_easy_database_transfers/) is an excellent solution for this. Heroku use it for cross-db support. Note that it works over network connections, which is very handy.