SlideShare a Scribd company logo
1 of 61
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
    create lib/tasks/legacy.rake
    insert added legacy adapter to end of database.yml
    insert added new load path to environment.rb
config/environment.rb
Rails::Initializer.run do |config|
  config.load_paths += %W( #{RAILS_ROOT}/app/
models/legacy )
end
config/database.yml
legacy:
  adapter: mysql
  encoding: utf8
  database: trucker_legacy
  username: root
  password:
app/models/legacy/legacy_base.rb
class 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
app/models/legacy/legacy_post.rb
class LegacyPost < LegacyBase
  set_table_name "blog_posts"

  def map
    {
      :name => self.headline.squish,
      :body => self.body.squish
    }
  end

end
app/models/legacy/legacy_post.rb
class 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
lib/tasks/legacy.rake
namespace :db do
  namespace :migrate do

   desc 'Migrates posts'
   task :posts => :environment do
     Trucker.migrate :posts
   end

  end
end
Let’s do some migrating.
Don’t forget to import
your legacy database!
$ rake db:migrate:posts

Migrating 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)
$ rake db:migrate:posts limit=5

Migrating 5 posts (1/10)
Migrating 5 posts (2/10)
Migrating 5 posts (3/10)
Migrating 5 posts (4/10)
Migrating 5 posts (5/10)
$ rake db:migrate:posts limit=5 offset=5

Migrating 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)
$ rake db:migrate:posts limit=5 offset=5 delete_all=true

Migrating 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)
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
     Trucker.migrate :pain_in_the_ass, :helper => pain_in_the_ass_migration
   end

  end
end

def pain_in_the_ass_migration
  # Custom code goes here
end
What about?!?
Trucker helps you move.
But you still need to
pack your stuff up.
Resources
•   http://github.com/mokolabs/trucker
•   http://github.com/mokolabs/trucker

•   http://github.com/mokolabs/
    trucker_sample_app
Special thanks
to Dave Thomas
The End

More Related Content

What's hot

Search as a Service with Xapian - Search Solutions 2009
Search as a Service with Xapian - Search Solutions 2009Search as a Service with Xapian - Search Solutions 2009
Search as a Service with Xapian - Search Solutions 2009
Richard Boulton
 

What's hot (19)

Real World Fun with ActiveResource
Real World Fun with ActiveResourceReal World Fun with ActiveResource
Real World Fun with ActiveResource
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Web development in Lua @ FOSDEM 2016
Web development in Lua @ FOSDEM 2016Web development in Lua @ FOSDEM 2016
Web development in Lua @ FOSDEM 2016
 
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
 
Elixir at Evercam (By Milos Mosic)
Elixir at Evercam (By Milos Mosic)Elixir at Evercam (By Milos Mosic)
Elixir at Evercam (By Milos Mosic)
 
JS Chicago Meetup 2/23/16 - Redux & Routes
JS Chicago Meetup 2/23/16 - Redux & RoutesJS Chicago Meetup 2/23/16 - Redux & Routes
JS Chicago Meetup 2/23/16 - Redux & Routes
 
A real-world Relay application in production - Stefano Masini - Codemotion Am...
A real-world Relay application in production - Stefano Masini - Codemotion Am...A real-world Relay application in production - Stefano Masini - Codemotion Am...
A real-world Relay application in production - Stefano Masini - Codemotion Am...
 
Presentation kyushu-2018
Presentation kyushu-2018Presentation kyushu-2018
Presentation kyushu-2018
 
Rack
RackRack
Rack
 
20121031 NGN Exchange Tips and Tricks by Michel De Rooij
20121031 NGN Exchange Tips and Tricks by Michel De Rooij20121031 NGN Exchange Tips and Tricks by Michel De Rooij
20121031 NGN Exchange Tips and Tricks by Michel De Rooij
 
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
 
Search as a Service with Xapian - Search Solutions 2009
Search as a Service with Xapian - Search Solutions 2009Search as a Service with Xapian - Search Solutions 2009
Search as a Service with Xapian - Search Solutions 2009
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and FluxTPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and Flux
 
ajax - the basics
ajax - the basicsajax - the basics
ajax - the basics
 
Consuming REST services with ActiveResource
Consuming REST services with ActiveResourceConsuming REST services with ActiveResource
Consuming REST services with ActiveResource
 
Foreman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple componentsForeman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple components
 
SF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDBSF Elixir Meetup - RethinkDB
SF Elixir Meetup - RethinkDB
 
Pydata2014
Pydata2014Pydata2014
Pydata2014
 
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
 

Similar to Trucker

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launched
Mat Schaffer
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 

Similar to Trucker (20)

Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launched
 
Convert modules from 6.x to 7.x
Convert modules from 6.x to 7.xConvert modules from 6.x to 7.x
Convert modules from 6.x to 7.x
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
CakePHP
CakePHPCakePHP
CakePHP
 
Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 

More from Patrick Crowley (9)

Compass
CompassCompass
Compass
 
Mobile web apps
Mobile web appsMobile web apps
Mobile web apps
 
Migrating Legacy Data
Migrating Legacy DataMigrating Legacy Data
Migrating Legacy Data
 
Paperclip
PaperclipPaperclip
Paperclip
 
CSS for iPhones
CSS for iPhonesCSS for iPhones
CSS for iPhones
 
Haml And Sass In 15 Minutes
Haml And Sass In 15 MinutesHaml And Sass In 15 Minutes
Haml And Sass In 15 Minutes
 
Rails For Legacy Apps
Rails For Legacy AppsRails For Legacy Apps
Rails For Legacy Apps
 
Headliner
HeadlinerHeadliner
Headliner
 
Styler
StylerStyler
Styler
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Trucker

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n