SlideShare a Scribd company logo
Migrating Legacy Data
Patrick Crowley
 Rob Kaufman
(We’re from SD Ruby)
Let’s talk about migrating
Suck => Less Suck
PHP => Rails
Perl => Rails
Java => Rails
Rails => Rails
Migrating = pain
• Develop new site
• Migrate data
• Deploy new site
Migrate data
• Dump database
• Drop some tables
• Rename attributes
• Tweak data by hand
• Import data into new app
• Pray things are okay
Sucks, right?
• Labor intensive
• Error prone
• One way trip
Trucker
Migrate legacy data
  (with less suck)
• 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)
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.
Some other things
  to think about
Encoding issues
• MySQL issues:
 “ALTER TABLE mytable
 CONVERT TO CHARACTER
 SET utf8;

• iconv
Java to the rescue?!?
JDBC Adapters vs
  ActiveRecord
• There are about 12 adapters in
  the wild for pure ActiveRecord

• The ActiveRecord adapter for
  sqlserver runs on Win/Unix,
  but Unix setup is complicated

• Text adapter does CSV, Tab,
  and other plain text formats
Migrating Legacy Data (Ruby Midwest)
Migrating Legacy Data (Ruby Midwest)
JDBC Adapters
ActiveRecord Tested:
 MySQL            Derby
 PostgreSQL       HSQLDB

 Oracle           H2

 Microsoft SQL    SQLite3

  Server           Informix

 DB2

 FireBird
MSSQL – An Example
• Download MSSQL driver
  (Google for it, they move it
  around a lot)

• Copy sqljdbc4.jar into
  RAILS_ROOT/lib

• Add require 'lib/sqljdbc4.jar' at
  the top of your environment.rb
  or application.rb
config/database.yml
legacy:
  adapter: jdbc
  username: USERNAME
  password: PASSWORD
  driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
  jdbc: sqlserver://63.134.199.59:1433
Take it live
• Run in prod when you can
• Run locally when you can't
 (Heroku, VPNs, etc)
Resources
•   http://github.com/mokolabs/trucker

•   http://github.com/mokolabs/
    trucker_sample_app

•   http://spkr8.com/t/3749
Special thanks
to Dave Thomas
The End

More Related Content

KEY
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
PDF
Intro to sbt-web
PDF
What's New in v2 - AnsibleFest London 2015
PDF
Ansible 2 and Ansible Galaxy 2
PDF
Scylla Summit 2022: ScyllaDB Embraces Wasm
PDF
Intro to Scala.js - Scala UG Cologne
PDF
PDXPortland - Dockerize Django
PDF
Fighting Against Chaotically Separated Values with Embulk
大規模環境でRailsと4年間付き合ってきて@ クックパッド * 食べログ合同勉強会
Intro to sbt-web
What's New in v2 - AnsibleFest London 2015
Ansible 2 and Ansible Galaxy 2
Scylla Summit 2022: ScyllaDB Embraces Wasm
Intro to Scala.js - Scala UG Cologne
PDXPortland - Dockerize Django
Fighting Against Chaotically Separated Values with Embulk

What's hot (20)

PDF
Put a Button on It: Removing Barriers to Going Fast
PPTX
Apache Camel K - Copenhagen
PDF
Using Ansible for Deploying to Cloud Environments
PDF
Altitude SF 2017: Stories from TED
KEY
MongoFr : MongoDB as a log Collector
PPTX
Chef advance
PPTX
Breaking Up With Your Data Center Presentation
PDF
Camel Day Italy 2021 - What's new in Camel 3
PPTX
Apache Camel K - Copenhagen v2
PPTX
Airflow and supervisor
PDF
Azkaban
PDF
PostgreSQL v9.4features
ODP
Jenkins Job Builder: our experience
PDF
Embuk internals
PPTX
Apache Camel K - Fredericia
PDF
RESTFul development with Apache sling
PPTX
Scalable Applications with Scala
PDF
Ansible Intro - June 2015 / Ansible Barcelona User Group
PDF
Ansible with AWS
PDF
Automating Workflows for Analytics Pipelines
Put a Button on It: Removing Barriers to Going Fast
Apache Camel K - Copenhagen
Using Ansible for Deploying to Cloud Environments
Altitude SF 2017: Stories from TED
MongoFr : MongoDB as a log Collector
Chef advance
Breaking Up With Your Data Center Presentation
Camel Day Italy 2021 - What's new in Camel 3
Apache Camel K - Copenhagen v2
Airflow and supervisor
Azkaban
PostgreSQL v9.4features
Jenkins Job Builder: our experience
Embuk internals
Apache Camel K - Fredericia
RESTFul development with Apache sling
Scalable Applications with Scala
Ansible Intro - June 2015 / Ansible Barcelona User Group
Ansible with AWS
Automating Workflows for Analytics Pipelines
Ad

Viewers also liked (11)

PPTX
10 tough decisions donor data migration decisions (Webinar hosted by Bloomera...
PPTX
CRMUG UK November 2015 - Data Migration Without Tears by Mike Feingold
PPT
Lsmw final with comments
PDF
The CRM Data Migration Process
PDF
Justifying Migration of legacy process control systems
PDF
Legacy Migration Overview
PDF
Software Modernization and Legacy Migration Primer
PDF
Enterprise Data Integration for Microsoft Dynamics CRM
PDF
Optimizing a Data Migration with an Assessment
PPTX
Preparing a data migration plan: A practical guide
PPTX
Capgemini CRM Modernization Services
10 tough decisions donor data migration decisions (Webinar hosted by Bloomera...
CRMUG UK November 2015 - Data Migration Without Tears by Mike Feingold
Lsmw final with comments
The CRM Data Migration Process
Justifying Migration of legacy process control systems
Legacy Migration Overview
Software Modernization and Legacy Migration Primer
Enterprise Data Integration for Microsoft Dynamics CRM
Optimizing a Data Migration with an Assessment
Preparing a data migration plan: A practical guide
Capgemini CRM Modernization Services
Ad

Similar to Migrating Legacy Data (Ruby Midwest) (20)

KEY
PDF
Migrating legacy data
PDF
Migrating Legacy Data
DOCX
PDF
Data herding
PDF
Data herding
KEY
深入淺出RoR
PPTX
12 Introduction to Rails
PDF
Migrating data into Drupal using the migrate module
PDF
Rails DB migrations
PDF
Rails Tips and Best Practices
PDF
Building a custom cms with django
PDF
Rails For Legacy Apps
PDF
Django Vs Rails
PDF
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
PPTX
Day 2 - Intro to Rails
PPTX
The long and the short of migrating to Drupal
PDF
Strategies for refactoring and migrating a big old project to be multilingual...
PDF
Free The Enterprise With Ruby & Master Your Own Domain
PDF
Hitch yourwagon
Migrating legacy data
Migrating Legacy Data
Data herding
Data herding
深入淺出RoR
12 Introduction to Rails
Migrating data into Drupal using the migrate module
Rails DB migrations
Rails Tips and Best Practices
Building a custom cms with django
Rails For Legacy Apps
Django Vs Rails
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
Day 2 - Intro to Rails
The long and the short of migrating to Drupal
Strategies for refactoring and migrating a big old project to be multilingual...
Free The Enterprise With Ruby & Master Your Own Domain
Hitch yourwagon

More from Patrick Crowley (7)

PDF
PDF
Mobile web apps
PDF
Paperclip
PDF
CSS for iPhones
PDF
Haml And Sass In 15 Minutes
PDF
Headliner
PDF
Mobile web apps
Paperclip
CSS for iPhones
Haml And Sass In 15 Minutes
Headliner

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MIND Revenue Release Quarter 2 2025 Press Release
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Migrating Legacy Data (Ruby Midwest)