Migrating to Spree, part 1: The Code

01 May 2011 – Warsaw

(continued from previous post)

The Plan

… was pretty simple. First, export products and categories to JSON files, using some very simple rake tasks:

namespace :export do
  desc 'export categories'
  task :categories => [:environment] do
    puts Category.all(:conditions => {:available => true}).to_json(:methods => [:name_pl, :name_en, :description_pl, :description_en])
  desc 'export products'
  task :products => [:environment] do
    puts Product.all(:conditions => {:available => true}).to_json(:methods => [:title_pl, :title_en, :description_pl, :description_en, :full_image_path])

Second, check the differences in schema (column names etc.) and, while trying to preserve IDs (pretty crucial for seamless import), import these JSON files into Spree store.

The final working import code is (I’ve decided that english will be the basic language for database content, while Polish Zloty will remain as the base currency) ended up as another rake tasks, this time within the codebase of new, Spree-powered engine lib/tasks/import.rake


It worked. Of course the import code required some work to achieve the final working state it’s now in, but basically it was one of the smoothest migrations I ever worked on.

Outstanding Issues

I still have this itching urge to import orders as well, for all our customers to have a nice order history, but this is quite a task and I’ve left that in the backlog, “to be done when I’ll have both the time and will”.

What’s Next?

Of course migrating data isn’t the only thing that had to be done in order to have a fully working new Spree-powered Bitspudlo.com.

But all the other steps are basically documented in a post on Spree group I wrote after completing the successful migration .