skwpspace yan pritzker’s home on the web

skwpspace is Yan Pritzker's home on the web

Blog :: Photography :: About Me

hello, i'm yan

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Get updates by email
Follow me on twitter

Top Posts

planypus

I'm the founder of Planypus, the place to share your plans!

cohesiveft

Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!

flickr

at the paradeat the parade@slava626@leorazellman and @smazo at bat17my poor ricohyou're wearing my sweaterthe graduatethe answer, my friend

Archives

Contact

Reach me at yan at pritzker.ws

Posted
29 February 2008 @ 7pm

Tagged
thoughts

ActiveRecord magic for importing across different database types

I recently had to import some old tickets from Collaboa (postgres) into Trac (sqlite3). After trying some conventional data dumping methods and getting frustrated with dealing with all the formatting issues, I came up with a rather simple solution by using ActiveRecord to do the dirty work with two database connections:

require rubygems
require active_record
$config = YAML.load_file(#{RAILS_ROOT}/config/database.yml)

module Trac
  class Ticket < ActiveRecord::Base
    establish_connection $config['trac'];
    set_table_name ticket
  end
end

module Collaboa
  class Ticket < ActiveRecord::Base
    establish_connection $config['collaboa']
    set_table_name tickets
  end
end

# To import tickets, just do this!
# Collaboa::Ticket.find(:all, :conditions => {:status_id => 1, :project_id => 1}).each do |t|
#   Trac::Ticket.create(:summary => t.summary, :description => t.content, :time => Time.now)
# end

Make sure you set up your database.yml properly

trac:
  adapter: sqlite3
  dbfile: # your file goes here

collaboa:
  adapter: postgresql
  # other settings...

Afterwards, all I had to fix some minor data issues with the imported data to make Trac happy:


sqlite> update ticket set type='boog',status='new',time=12345,changetime=12345;

Voila!


It’s Icy Outside When marketing has no clue