Skip to content

Instantly share code, notes, and snippets.

@NickClark
Created October 22, 2010 19:46
Show Gist options
  • Save NickClark/641243 to your computer and use it in GitHub Desktop.
Save NickClark/641243 to your computer and use it in GitHub Desktop.
legacy_import.rake
namespace :app_name do
desc "Import data from old database"
task :legacy_data_import => :environment do
class LegacyDB < ActiveRecord::Base
self.abstract_class = true
establish_connection(:legacy)
end
#check for column named 'class', this will conflict with Rails,
#so we will change the column name
LegacyDB.connection.execute("ALTER TABLE `database`.`table_name` CHANGE COLUMN `class` `the_class` VARCHAR(50) NULL DEFAULT NULL ;") rescue # if class_column_exists
module Legacy
class TableName < LegacyDB
end
end
Legacy::TableName.each do |t|
puts t.the_class
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment