Trucker
Let’s talk about   migrating
Suck => Less Suck
PHP => Rails
Perl => Rails
Java => Rails
Rails => Rails
Migrating = pain
•   Develop new site
•Develop new site• Migrate data
•Develop new site• Migrate data• Deploy new site
Migrate data
•   Dump database
•Dump database• Drop some tables
•Dump database• Drop some tables• Rename attributes
•Dump database• Drop some tables• Rename attributes• Tweak data by hand
•Dump database• Drop some tables• Rename attributes• Tweak data by hand• Import data into new app
•Dump database• Drop some tables• Rename attributes• Tweak data by hand• Import data into new app• Pray things are okay
Sucks, right?
•   Labor intensive
•Labor intensive• Error prone
•Labor intensive• Error prone• One way trip
Trucker
Migrate legacy data  (with less suck)
•   Migrate data from day one
•Migrate data from day one• Improve data over time
•Migrate data from day one• Improve data over time• Launch with confidence
rake +legacy classes +migration helper
Let’s get started
sudo gem install trucker
config.gem “trucker”
script/generate truck
$ script/generate truck    create app/models/legacy    create app/models/legacy/legacy_base.rb    exists lib/tasks    crea...
config/environment.rbRails::Initializer.run do |config|  config.load_paths += %W( #{RAILS_ROOT}/app/models/legacy )end
config/database.ymllegacy:  adapter: mysql  encoding: utf8  database: trucker_legacy  username: root  password:
app/models/legacy/legacy_base.rbclass LegacyBase < ActiveRecord::Base  self.abstract_class = true  establish_connection "l...
app/models/legacy/legacy_post.rbclass LegacyPost < LegacyBase  set_table_name "blog_posts"  def map    {      :name => sel...
app/models/legacy/legacy_post.rbclass LegacyPost < LegacyBase  set_table_name "blog_posts"  def map    {      :name => twe...
lib/tasks/legacy.rakenamespace :db do  namespace :migrate do   desc Migrates posts   task :posts => :environment do     Tr...
Let’s do some migrating.
Don’t forget to importyour legacy database!
$ rake db:migrate:postsMigrating all posts (1/10)Migrating all posts (2/10)Migrating all posts (3/10)Migrating all posts (...
$ rake db:migrate:posts limit=5Migrating 5 posts (1/10)Migrating 5 posts (2/10)Migrating 5 posts (3/10)Migrating 5 posts (...
$ rake db:migrate:posts limit=5 offset=5Migrating 5 posts after 5 (6/10)Migrating 5 posts after 5 (7/10)Migrating 5 posts ...
$ rake db:migrate:posts limit=5 offset=5 delete_all=trueMigrating 5 posts after 5 (6/10)Migrating 5 posts after 5 (7/10)Mi...
DEMO
Use helper method for custom migrations
namespace :db do  namespace :migrate do   desc Migrate pain_in_the_ass model   task :pain_in_the_ass => :environment do   ...
What about?!?
Trucker helps you move.
But you still need topack your stuff up.
Resources
•   http://github.com/mokolabs/trucker
•   http://github.com/mokolabs/trucker•   http://github.com/mokolabs/    trucker_sample_app
Special thanksto Dave Thomas
The End
Trucker
Trucker
Trucker
Trucker
Trucker
Upcoming SlideShare
Loading in...5
×

Trucker

1,276

Published on

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

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,276
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

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
  • Trucker

    1. 1. Trucker
    2. 2. Let’s talk about migrating
    3. 3. Suck => Less Suck
    4. 4. PHP => Rails
    5. 5. Perl => Rails
    6. 6. Java => Rails
    7. 7. Rails => Rails
    8. 8. Migrating = pain
    9. 9. • Develop new site
    10. 10. •Develop new site• Migrate data
    11. 11. •Develop new site• Migrate data• Deploy new site
    12. 12. Migrate data
    13. 13. • Dump database
    14. 14. •Dump database• Drop some tables
    15. 15. •Dump database• Drop some tables• Rename attributes
    16. 16. •Dump database• Drop some tables• Rename attributes• Tweak data by hand
    17. 17. •Dump database• Drop some tables• Rename attributes• Tweak data by hand• Import data into new app
    18. 18. •Dump database• Drop some tables• Rename attributes• Tweak data by hand• Import data into new app• Pray things are okay
    19. 19. Sucks, right?
    20. 20. • Labor intensive
    21. 21. •Labor intensive• Error prone
    22. 22. •Labor intensive• Error prone• One way trip
    23. 23. Trucker
    24. 24. Migrate legacy data (with less suck)
    25. 25. • Migrate data from day one
    26. 26. •Migrate data from day one• Improve data over time
    27. 27. •Migrate data from day one• Improve data over time• Launch with confidence
    28. 28. rake +legacy classes +migration helper
    29. 29. Let’s get started
    30. 30. sudo gem install trucker
    31. 31. config.gem “trucker”
    32. 32. script/generate truck
    33. 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. 34. config/environment.rbRails::Initializer.run do |config| config.load_paths += %W( #{RAILS_ROOT}/app/models/legacy )end
    35. 35. config/database.ymllegacy: adapter: mysql encoding: utf8 database: trucker_legacy username: root password:
    36. 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. 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. 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. 39. lib/tasks/legacy.rakenamespace :db do namespace :migrate do desc Migrates posts task :posts => :environment do Trucker.migrate :posts end endend
    40. 40. Let’s do some migrating.
    41. 41. Don’t forget to importyour legacy database!
    42. 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. 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. 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. 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. 46. DEMO
    47. 47. Use helper method for custom migrations
    48. 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. 49. What about?!?
    50. 50. Trucker helps you move.
    51. 51. But you still need topack your stuff up.
    52. 52. Resources
    53. 53. • http://github.com/mokolabs/trucker
    54. 54. • http://github.com/mokolabs/trucker• http://github.com/mokolabs/ trucker_sample_app
    55. 55. Special thanksto Dave Thomas
    56. 56. The End
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×