Uploaded on

Patrick Crowley talks about Trucker, a new gem that makes it easier to migrate legacy data into Rails app.

Patrick Crowley talks about Trucker, a new gem that makes it easier to migrate legacy data into Rails app.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,215
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
10
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. Trucker
  • 2. Let’s talk about migrating
  • 3. Suck => Less Suck
  • 4. PHP => Rails
  • 5. Perl => Rails
  • 6. Java => Rails
  • 7. Rails => Rails
  • 8. Migrating = pain
  • 9. • Develop new site
  • 10. •Develop new site• Migrate data
  • 11. •Develop new site• Migrate data• Deploy new site
  • 12. Migrate data
  • 13. • Dump database
  • 14. •Dump database• Drop some tables
  • 15. •Dump database• Drop some tables• Rename attributes
  • 16. •Dump database• Drop some tables• Rename attributes• Tweak data by hand
  • 17. •Dump database• Drop some tables• Rename attributes• Tweak data by hand• Import data into new app
  • 18. •Dump database• Drop some tables• Rename attributes• Tweak data by hand• Import data into new app• Pray things are okay
  • 19. Sucks, right?
  • 20. • Labor intensive
  • 21. •Labor intensive• Error prone
  • 22. •Labor intensive• Error prone• One way trip
  • 23. Trucker
  • 24. Migrate legacy data (with less suck)
  • 25. • Migrate data from day one
  • 26. •Migrate data from day one• Improve data over time
  • 27. •Migrate data from day one• Improve data over time• Launch with confidence
  • 28. rake +legacy classes +migration helper
  • 29. Let’s get started
  • 30. sudo gem install trucker
  • 31. config.gem “trucker”
  • 32. script/generate truck
  • 33. $ script/generate truck create app/models/legacy create app/models/legacy/legacy_base.rb exists lib/tasks create lib/tasks/legacy.rake insert added legacy adapter to end of database.yml insert added new load path to environment.rb
  • 34. config/environment.rbRails::Initializer.run do |config| config.load_paths += %W( #{RAILS_ROOT}/app/models/legacy )end
  • 35. config/database.ymllegacy: adapter: mysql encoding: utf8 database: trucker_legacy username: root password:
  • 36. app/models/legacy/legacy_base.rbclass LegacyBase < ActiveRecord::Base self.abstract_class = true establish_connection "legacy" def migrate new_record = self.class.to_s.gsub(/Legacy/,::).constantize.new(map) new_record[:id] = self.id new_record.save end
  • 37. app/models/legacy/legacy_post.rbclass LegacyPost < LegacyBase set_table_name "blog_posts" def map { :name => self.headline.squish, :body => self.body.squish } endend
  • 38. app/models/legacy/legacy_post.rbclass LegacyPost < LegacyBase set_table_name "blog_posts" def map { :name => tweak(self.headline.squish), :body => self.body.squish } end def tweak(name) name.capitalize.gsub(/teh/, "the") end
  • 39. lib/tasks/legacy.rakenamespace :db do namespace :migrate do desc Migrates posts task :posts => :environment do Trucker.migrate :posts end endend
  • 40. Let’s do some migrating.
  • 41. Don’t forget to importyour legacy database!
  • 42. $ rake db:migrate:postsMigrating all posts (1/10)Migrating all posts (2/10)Migrating all posts (3/10)Migrating all posts (4/10)Migrating all posts (5/10)Migrating all posts (6/10)Migrating all posts (7/10)Migrating all posts (8/10)Migrating all posts (9/10)Migrating all posts (10/10)
  • 43. $ rake db:migrate:posts limit=5Migrating 5 posts (1/10)Migrating 5 posts (2/10)Migrating 5 posts (3/10)Migrating 5 posts (4/10)Migrating 5 posts (5/10)
  • 44. $ rake db:migrate:posts limit=5 offset=5Migrating 5 posts after 5 (6/10)Migrating 5 posts after 5 (7/10)Migrating 5 posts after 5 (8/10)Migrating 5 posts after 5 (9/10)Migrating 5 posts after 5 (10/10)
  • 45. $ rake db:migrate:posts limit=5 offset=5 delete_all=trueMigrating 5 posts after 5 (6/10)Migrating 5 posts after 5 (7/10)Migrating 5 posts after 5 (8/10)Migrating 5 posts after 5 (9/10)Migrating 5 posts after 5 (10/10)
  • 46. DEMO
  • 47. Use helper method for custom migrations
  • 48. namespace :db do namespace :migrate do desc Migrate pain_in_the_ass model task :pain_in_the_ass => :environment do Trucker.migrate :pain_in_the_ass, :helper => pain_in_the_ass_migration end endenddef pain_in_the_ass_migration # Custom code goes hereend
  • 49. What about?!?
  • 50. Trucker helps you move.
  • 51. But you still need topack your stuff up.
  • 52. Resources
  • 53. • http://github.com/mokolabs/trucker
  • 54. • http://github.com/mokolabs/trucker• http://github.com/mokolabs/ trucker_sample_app
  • 55. Special thanksto Dave Thomas
  • 56. The End