Skip to content

Commit

Permalink
Merged pull request #3 from sideshowbandana/master.
Browse files Browse the repository at this point in the history
move across dbs
  • Loading branch information
winton committed Apr 26, 2011
2 parents be5b7d9 + 2759efb commit 61f0e6d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/mover.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def move_to(to_class, options={})
:table => from_class.table_name :table => from_class.table_name
} }
to = { to = {
:database => to_class.connection.current_database,
:columns => to_class.column_names, :columns => to_class.column_names,
:table => to_class.table_name :table => to_class.table_name
} }
Expand Down Expand Up @@ -104,7 +105,7 @@ def move_to(to_class, options={})


if options[:quick] if options[:quick]
connection.execute(<<-SQL) connection.execute(<<-SQL)
INSERT INTO #{to[:table]} (#{insert.keys.join(', ')}) INSERT INTO #{to[:database]}.#{to[:table]} (#{insert.keys.join(', ')})
SELECT #{insert.values.join(', ')} SELECT #{insert.values.join(', ')}
FROM #{from[:table]} FROM #{from[:table]}
#{where} #{where}
Expand All @@ -117,9 +118,8 @@ def move_to(to_class, options={})
"#{to[:table]}.#{column} = #{from[:table]}.#{value}" "#{to[:table]}.#{column} = #{from[:table]}.#{value}"
end end
end end

connection.execute(<<-SQL) connection.execute(<<-SQL)
INSERT INTO #{to[:table]} (#{insert.keys.join(', ')}) INSERT INTO #{ to[:database]}.#{to[:table]} (#{insert.keys.join(', ')})
SELECT #{insert.values.join(', ')} SELECT #{insert.values.join(', ')}
FROM #{from[:table]} FROM #{from[:table]}
#{where} #{where}
Expand Down Expand Up @@ -191,4 +191,4 @@ def move_to(to_class, options={})
end end
end end


ActiveRecord::Base.send(:include, Mover) ActiveRecord::Base.send(:include, Mover)

0 comments on commit 61f0e6d

Please sign in to comment.