Skip to content

Instantly share code, notes, and snippets.

@ocean
Created May 21, 2009 05:45
Show Gist options
  • Save ocean/115306 to your computer and use it in GitHub Desktop.
Save ocean/115306 to your computer and use it in GitHub Desktop.
I got the idea, and most of this code, from this post at The Killswitch Collective:
http://www.killswitchcollective.com/articles/45_legacy_data_migration_with_activerecord
I'm sure that other bits of the code aren't going to work either, like the "if" statement
in the "publish" boolean field, I suppose there will be another way to make that work.
class LegacyBase < ActiveRecord::Base
establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "",
:password => "",
:database => "ws_prosecutions"
)
end
class LegacyProsecutions < LegacyBase
set_table_name "prosecutions"
def migrate_me!
prosecution = Prosecution.create(
:defendant => self.Defendant,
:section => (self.Section || '') + " -- " + (self.zSearch_sec_reg_1 || '') + " - " + (self.zSearch_sec_reg_2 || '') + " - " + (self.zSearch_sec_reg_3 || ''),
:description => self.Description,
:background => self.Background,
:conviction_date => (self.Conviction\ Date || '').to_date,
:court => self.Court,
:fine => self.Fine,
:outcome_summary => self.Outcome\ Summary,
:charge_number => self.Charge_Number || '',
:date_added => (self.Date\ Added || '').to_date,
:regulation => self.Regulation || '',
:offence_date => self.Offence_Date,
:trading_name => self.Trading_Name || '',
:inspector => self.Inspector,
:costs => self.Costs || '',
:file_number => self.File_Number,
:publish => if self.Publish.downcase == "yes" then 1 else 0,
:image => self.Image || ''
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment