Permalink
Browse files

Updated mover to be able to move data across databases in mysql

  • Loading branch information...
1 parent be5b7d9 commit 2759efb67de7032a51396d3aaa8e53fb7e3ab727 Kyle committed Apr 20, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/mover.rb
View
@@ -39,6 +39,7 @@ def move_to(to_class, options={})
:table => from_class.table_name
}
to = {
+ :database => to_class.connection.current_database,
:columns => to_class.column_names,
:table => to_class.table_name
}
@@ -104,7 +105,7 @@ def move_to(to_class, options={})
if options[:quick]
connection.execute(<<-SQL)
- INSERT INTO #{to[:table]} (#{insert.keys.join(', ')})
+ INSERT INTO #{to[:database]}.#{to[:table]} (#{insert.keys.join(', ')})
SELECT #{insert.values.join(', ')}
FROM #{from[:table]}
#{where}
@@ -117,9 +118,8 @@ def move_to(to_class, options={})
"#{to[:table]}.#{column} = #{from[:table]}.#{value}"
end
end
-
connection.execute(<<-SQL)
- INSERT INTO #{to[:table]} (#{insert.keys.join(', ')})
+ INSERT INTO #{ to[:database]}.#{to[:table]} (#{insert.keys.join(', ')})
SELECT #{insert.values.join(', ')}
FROM #{from[:table]}
#{where}
@@ -191,4 +191,4 @@ def move_to(to_class, options={})
end
end
-ActiveRecord::Base.send(:include, Mover)
+ActiveRecord::Base.send(:include, Mover)

0 comments on commit 2759efb

Please sign in to comment.