Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merged pull request #3 from sideshowbandana/master.

move across dbs
  • Loading branch information...
commit 61f0e6de83bc485d3ae0c6415865e1eaac28c643 2 parents be5b7d9 + 2759efb
@winton authored
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/mover.rb
View
8 lib/mover.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.