Mysql to postgres rake task

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 [email protected]
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 S. ------------------------ [email protected]

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 S. [email protected]

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 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 S.
mailto:[email protected]
http://www.schuerig.de/michael/

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 [email protected]

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.

end
    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.

On Sat, May 16, 2009 at 7:29 PM, magic_hat [email protected]
wrote:

the yaml_db plugin looked promising, but it’s bombing because of
unbalanced quotes in some of the content

ouch. Can you post the stack trace and an example data row that’s
causing the problem?


Hassan S. ------------------------ [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs