Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move across dbs #3

Merged
merged 1 commit into from Apr 26, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/mover.rb
Expand Up @@ -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
}
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -191,4 +191,4 @@ def move_to(to_class, options={})
end
end

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