mosql 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43cb64bb52ef41955332728b063f24470d73c134
4
- data.tar.gz: 9ddb444a959cdce77da58255fa64f4704cc4f201
3
+ metadata.gz: 7ab1024ecdb478cb92b0c2041f7d5f52a67ec0d3
4
+ data.tar.gz: 2b88ed3d4bb0723f67170d645d61e34b62d29dc6
5
5
  SHA512:
6
- metadata.gz: 7260354422d7fad24eb8a018f7bf26108e7d3a86e502c0910df72cea011ecb58ee0c26065f8562940b4cca9bff2db06d07016aa4a83bd1dd4c1c0ee04c132f7d
7
- data.tar.gz: 7bc1b499a41c0285770f26559c117e864e072490466f9aaabb7bb33093d5202767bc42d98525b2cf5a4405f79d88c5e4704df5aad75df918ad1b97ad1d5f15b8
6
+ metadata.gz: 5e8cc02a48b261391e0a161e0c35fb92113cc85f9e7436ed14bb9a4e0b54f4389f13093a02f9af6b516bd6d1d1db93202d5e8fd52c76d927564ead0733eb2d1d
7
+ data.tar.gz: d6a2c35555a5e8d4c99596f8c0cd212dca2546932a023cc1d7686ea6581ef0387813179817ce368cf06dff50753b927cc1ecba8be3bc82b44ff52519c141e31c
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mosql (0.4.0)
4
+ mosql (0.4.1)
5
+ bson (~> 1.10)
5
6
  bson_ext
6
7
  json
7
8
  log4r
@@ -14,24 +15,24 @@ PATH
14
15
  GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
17
- bson (1.10.2)
18
- bson_ext (1.10.2)
19
- bson (~> 1.10.2)
18
+ bson (1.11.1)
19
+ bson_ext (1.11.1)
20
+ bson (~> 1.11.1)
20
21
  json (1.8.1)
21
22
  log4r (1.1.10)
22
23
  metaclass (0.0.4)
23
- minitest (3.0.0)
24
- mocha (1.0.0)
24
+ minitest (5.4.2)
25
+ mocha (1.1.0)
25
26
  metaclass (~> 0.0.1)
26
- mongo (1.10.2)
27
- bson (= 1.10.2)
27
+ mongo (1.11.1)
28
+ bson (= 1.11.1)
28
29
  mongoriver (0.4.0)
29
30
  bson_ext
30
31
  log4r
31
32
  mongo (>= 1.7)
32
33
  pg (0.17.1)
33
34
  rake (10.3.2)
34
- sequel (4.14.0)
35
+ sequel (4.16.0)
35
36
 
36
37
  PLATFORMS
37
38
  ruby
data/README.md CHANGED
@@ -212,7 +212,24 @@ e.g.
212
212
  mosql --mongo mongdb://$USER@$PASSWORD:$HOST/admin
213
213
  ```
214
214
 
215
- I have not yet tested using MoSQL with 2.4's "roles" support. Drop me
215
+ In order to use MongoDB 2.4's "roles" support (which is different from that in
216
+ 2.6), you need to create the user in the admin database, give it explicit read
217
+ access to the databases you want to copy *and* to the `local` database, and
218
+ specify authSource in the URL. eg, connect to `mydb/admin` with the mongo shell
219
+ and run:
220
+
221
+ ```
222
+ > db.addUser({user: "replicator", pwd: "PASSWORD", roles: [], otherDBRoles: {local: ["read"], sourceDb: ["read"]}})
223
+ ```
224
+
225
+ (Note that `roles: []` ensures that this user has no special access to the
226
+ `admin` database.) Now specify:
227
+
228
+ ```
229
+ mosql --mongo mongdb://$USER@$PASSWORD:$HOST/sourceDb?authSource=admin
230
+ ```
231
+
232
+ I have not yet tested using MoSQL with 2.6's rewritten "roles" support. Drop me
216
233
  a note if you figure out anything I should know.
217
234
 
218
235
  ## Sharded clusters
@@ -98,6 +98,11 @@ module MoSQL
98
98
  opts.on("--unsafe", "Ignore rows that cause errors on insert") do
99
99
  @options[:unsafe] = true
100
100
  end
101
+
102
+ # eg, --oplog-filter '{"ns": {"$regex": "^somedb[0-9]*\\.collection$"}}'
103
+ opts.on("--oplog-filter [filter]", "An additional JSON filter for the oplog query") do |filter|
104
+ @options[:oplog_filter] = JSON.parse(filter)
105
+ end
101
106
  end
102
107
 
103
108
  optparse.parse!(@args)
@@ -159,10 +159,24 @@ module MoSQL
159
159
  val
160
160
  end
161
161
 
162
- def fetch_special_source(obj, source)
162
+ def fetch_exists(obj, dotted)
163
+ pieces = dotted.split(".")
164
+ while pieces.length > 1
165
+ key = pieces.shift
166
+ obj = obj[key]
167
+ return false unless obj.is_a?(Hash)
168
+ end
169
+ obj.has_key?(pieces.first)
170
+ end
171
+
172
+ def fetch_special_source(obj, source, original)
163
173
  case source
164
174
  when "$timestamp"
165
175
  Sequel.function(:now)
176
+ when /^\$exists (.+)/
177
+ # We need to look in the cloned original object, not in the version that
178
+ # has had some fields deleted.
179
+ fetch_exists(original, $1)
166
180
  else
167
181
  raise SchemaError.new("Unknown source: #{source}")
168
182
  end
@@ -188,7 +202,12 @@ module MoSQL
188
202
  def transform(ns, obj, schema=nil)
189
203
  schema ||= find_ns!(ns)
190
204
 
191
- obj = obj.dup
205
+ original = obj
206
+
207
+ # Do a deep clone, because we're potentially going to be
208
+ # mutating embedded objects.
209
+ obj = BSON.deserialize(BSON.serialize(obj))
210
+
192
211
  row = []
193
212
  schema[:columns].each do |col|
194
213
 
@@ -196,7 +215,7 @@ module MoSQL
196
215
  type = col[:type]
197
216
 
198
217
  if source.start_with?("$")
199
- v = fetch_special_source(obj, source)
218
+ v = fetch_special_source(obj, source, original)
200
219
  else
201
220
  v = fetch_and_delete_dotted(obj, source)
202
221
  case v
@@ -170,7 +170,7 @@ module MoSQL
170
170
  if tail_from.is_a? Time
171
171
  tail_from = tailer.most_recent_position(tail_from)
172
172
  end
173
- tailer.tail(:from => tail_from)
173
+ tailer.tail(:from => tail_from, :filter => options[:oplog_filter])
174
174
  until @done
175
175
  tailer.stream(1000) do |op|
176
176
  handle_op(op)
@@ -1,3 +1,3 @@
1
1
  module MoSQL
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  %w[sequel pg mongo bson_ext rake log4r json
20
20
  ].each { |dep| gem.add_runtime_dependency(dep) }
21
21
  gem.add_runtime_dependency "mongoriver", "0.4"
22
+ gem.add_runtime_dependency "bson", "~> 1.10"
22
23
 
23
24
  gem.add_development_dependency "minitest"
24
25
  gem.add_development_dependency "mocha"
@@ -262,7 +262,7 @@ EOF
262
262
  @streamer.handle_op({ 'ns' => 'mosql_test.collection',
263
263
  'op' => 'u',
264
264
  'o2' => { '_id' => 'a' },
265
- 'o' => { 'var' => 1 << 70 },
265
+ 'o' => { 'var' => 1 << 62 },
266
266
  })
267
267
  end
268
268
  end
@@ -272,7 +272,7 @@ EOF
272
272
  @streamer.handle_op({ 'ns' => 'mosql_test.collection',
273
273
  'op' => 'u',
274
274
  'o2' => { '_id' => 'a' },
275
- 'o' => { 'var' => 1 << 70 },
275
+ 'o' => { 'var' => 1 << 62 },
276
276
  })
277
277
  assert_equal(0, sequel[:sqltable].where(:_id => 'a').count)
278
278
  end
@@ -343,6 +343,26 @@ db:
343
343
  - mosql_created:
344
344
  :source: $timestamp
345
345
  :type: timestamp
346
+ existence:
347
+ :meta:
348
+ :table: b_table
349
+ :columns:
350
+ - _id: TEXT
351
+ - has_foo:
352
+ :source: $exists foo
353
+ :type: BOOLEAN
354
+ - has_foo_bar:
355
+ :source: $exists foo.bar
356
+ :type: BOOLEAN
357
+ exists_and_value:
358
+ :meta:
359
+ :table: c_table
360
+ :columns:
361
+ - _id: TEXT
362
+ - foo: TEXT
363
+ - has_foo:
364
+ :source: $exists foo
365
+ :type: BOOLEAN
346
366
  invalid:
347
367
  :meta:
348
368
  :table: invalid
@@ -362,6 +382,28 @@ EOF
362
382
  assert_equal(['a', Sequel.function(:now)], r)
363
383
  end
364
384
 
385
+ it 'translates $exists' do
386
+ r = @othermap.transform('db.existence', { '_id' => 'a' })
387
+ assert_equal(['a', false, false], r)
388
+ r = @othermap.transform('db.existence', { '_id' => 'a', 'foo' => nil })
389
+ assert_equal(['a', true, false], r)
390
+ r = @othermap.transform('db.existence', { '_id' => 'a', 'foo' => {} })
391
+ assert_equal(['a', true, false], r)
392
+ r = @othermap.transform('db.existence', { '_id' => 'a', 'foo' => {'bar' => nil} })
393
+ assert_equal(['a', true, true], r)
394
+ r = @othermap.transform('db.existence', { '_id' => 'a', 'foo' => {'bar' => 42} })
395
+ assert_equal(['a', true, true], r)
396
+ end
397
+
398
+ it 'can get $exists and value' do
399
+ r = @othermap.transform('db.exists_and_value', { '_id' => 'a' })
400
+ assert_equal(['a', nil, false], r)
401
+ r = @othermap.transform('db.exists_and_value', { '_id' => 'a', 'foo' => nil })
402
+ assert_equal(['a', nil, true], r)
403
+ r = @othermap.transform('db.exists_and_value', { '_id' => 'a', 'foo' => 'xxx' })
404
+ assert_equal(['a', 'xxx', true], r)
405
+ end
406
+
365
407
  it 'rejects unknown specials' do
366
408
  assert_raises(MoSQL::SchemaError) do
367
409
  r = @othermap.transform('db.invalid', { '_id' => 'a' })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mosql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nelson Elhage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bson
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.10'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.10'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: minitest
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -213,4 +227,3 @@ test_files:
213
227
  - test/functional/streamer.rb
214
228
  - test/functional/transform.rb
215
229
  - test/unit/lib/mosql/schema.rb
216
- has_rdoc: