Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Fixed bug when using a renamed _id field and an update operation whic…
Browse files Browse the repository at this point in the history
…h replaces a documents fields entirely.
  • Loading branch information
mark-roggenkamp-snapav committed Dec 31, 2014
1 parent 85f4074 commit dca0ec2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mosql/streamer.rb
Expand Up @@ -241,7 +241,7 @@ def handle_op(op)
keys = {}
primary_sql_keys.each do |key|
source = schema[:columns].find {|c| c[:name] == key }[:source]
keys[key] = selector[source]
keys[source] = selector[source]
end

log.debug("upsert #{ns}: #{keys}")
Expand Down
12 changes: 12 additions & 0 deletions test/functional/streamer.rb
Expand Up @@ -95,6 +95,18 @@ def build_streamer
assert_equal(27, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var])
end

it 'handle "u" ops without _id and a renamed _id mapping' do
o = { '_id' => BSON::ObjectId.new, 'var' => 17 }
@adapter.upsert_ns('mosql_test.renameid', o)

@streamer.handle_op({ 'ns' => 'mosql_test.renameid',
'op' => 'u',
'o2' => { '_id' => o['_id'] },
'o' => { 'goats' => 27 }
})
assert_equal(27, sequel[:sqltable2].where(:id => o['_id'].to_s).select.first[:goats])
end

it 'applies ops performed via applyOps' do
o = { '_id' => BSON::ObjectId.new, 'var' => 17 }
@adapter.upsert_ns('mosql_test.collection', o)
Expand Down

0 comments on commit dca0ec2

Please sign in to comment.