I finally got fed up with the bugs in Rails 1.0 handling of mysql connections and have decided to move to postgres. I have talked about the move and even migrated my DDL to the database agnostic schema language. The one thing I had not yet thought about was how to move my data.
After doing a little bit of asking and searching I decided to just dump my data out the databse to fixtures and then reload these fixtures. This is surprisingly simple using the rake task.
This is Mysql specific due to the use of
select\_values(‘show tables’) but apparently sqlite usues select\_values(‘.table’) and postgres uses the following.
This worked like a charm except when my data contained embedded ERB directives because when rails loads the fixtures it attempts to evaluate the fixture as an ERB script. In this scenario I just needed to nip into the read\_fixture\_files method in $RUBY\_HOME\\activerecord-1.13.2\\lib\\active\_record\\fixtures.rb
and comment out the erb rendering while I imported my data.
Update: The code for this can be found is available in dump_fixtures.rake