Created
October 22, 2010 19:46
-
-
Save NickClark/641243 to your computer and use it in GitHub Desktop.
legacy_import.rake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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