lib/gamma/importer/replace.rb in gamma-0.1.3 vs lib/gamma/importer/replace.rb in gamma-0.1.4
- old
+ new
@@ -20,16 +20,15 @@
def batch_sync
columns = @table.in_exist_columns & @table.out_exist_columns
primary_key = "id" # TODO: Fixme
current_in_pid = 0
- current_in_offset = 0
while true do
select_columns = columns.map { |c| "`#{c}`" }.join(",")
break unless select_columns.present?
- in_query = "SELECT #{select_columns} FROM #{@table.table_name} WHERE id > #{current_in_pid} LIMIT #{BATCH_SIZE}"
+ in_query = "SELECT #{select_columns} FROM #{@table.table_name} WHERE #{primary_key} > #{current_in_pid} ORDER BY #{primary_key} ASC LIMIT #{BATCH_SIZE}"
logger.info(in_query) if ENV["DEBUG"]
in_records = @in_client.client.query(in_query).to_a
break unless in_records.present?
@@ -42,10 +41,9 @@
insert_out_record(in_record)
end
end
current_in_pid = in_records.last[primary_key]
- current_in_offset = current_in_offset + BATCH_SIZE
end
rescue => e
logger.error("Sync Error #{@table.table_name} \n #{e}\n #{e.backtrace.join("\n")}".red)
end