Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

move across dbs #3

Merged
merged 1 commit into from

2 participants

@sideshowbandana

Hey guys,
I updated mover to be able to move data across databases. In the event that someone has an AR class that uses a different db connection this should allow mover to move the data to the right db (provided it's on the same machine)

@winton winton referenced this pull request from a commit
@winton Merged pull request #3 from sideshowbandana/master.
move across dbs
61f0e6d
@winton winton merged commit 61f0e6d into winton:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 20, 2011
This page is out of date. Refresh to see the latest.
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)
Something went wrong with that request. Please try again.