lib/lhm/chunker.rb in lhm-1.3.0 vs lib/lhm/chunker.rb in lhm-2.0.0

- old
+ new

@@ -41,12 +41,12 @@ [chunk * @stride + @start - 1, @limit].min end def copy(lowest, highest) "insert ignore into `#{ destination_name }` (#{ columns }) " + - "select #{ columns } from `#{ origin_name }` " + - "where `id` between #{ lowest } and #{ highest }" + "select #{ select_columns } from `#{ origin_name }` " + + "#{ conditions } #{ origin_name }.`id` between #{ lowest } and #{ highest }" end def select_start start = connection.select_value("select min(id) from #{ origin_name }") start ? start.to_i : nil @@ -61,19 +61,27 @@ @throttle / 1000.0 end private + def conditions + @migration.conditions ? "#{@migration.conditions} and" : "where" + end + def destination_name @migration.destination.name end def origin_name @migration.origin.name end def columns @columns ||= @migration.intersection.joined + end + + def select_columns + @select_columns ||= @migration.intersection.typed(origin_name) end def validate if @start && @limit && @start > @limit error("impossible chunk options (limit must be greater than start)")