stripe/mosql — pull request #63 by macobo (2014-08-28 22:58:25+00:00)
Title: Update tailers for mongoriver 0.4 (tokumx support)

This commit is a companion to https://github.com/stripe/mongoriver/pull/11, which adds support for tokumx as mongodb alternative and revamps much of the tailer api.

r? @ebroder

-----

For reference, notes on how I test this since this took a little bit of puzzling:

``` yaml
# Collection.yaml
test:
test_collection:
:columns:
- id:
:source: _id
:type: TEXT
- name:
:source: nested.name
:type: TEXT
- number:
:source: nested.int
:type: INTEGER
- title: TEXT
:meta:
:table: blog_posts
:extra_props: true
```

Create an mongodb collection, insert a sample: `conn["test"]["test_collection"].insert({title: "title", nested: {name: "name1", int: 5}})`

Start mosql, see if it creates table, see if database contains the record:
``` ruby
sql = Sequel.connect("postgres://postgres@localhost")
tailer_db = sql[:mosql_tailers]
tailer_db.all

db2 = sql[:blog_posts]
db2.all
```

Try to update and insert more to see if new ones are added:
```ruby
conn["test"]["test_collection"].insert({title: "title2", nested: {name: "name1", int: 5}})
conn["test"]["test_collection"].update({title: "title2"}, {'$set' => {'nested.int' => 99}})
# restart mosql here, look to make sure no new fields are added and changes are picked up
db2.all
conn["test"]["test_collection"].update({title: "title2"}, {'$set' => {'nested.int' => 90}})
```

Testing if smooth updating works:
```
info = tailer_db.first
Oplog_collection.remove()
conn.drop_database("test")
sql.drop_table('blog_posts')
sql.drop_table('mosql_tailers')

create old style table and put an entry in it
sql.create_table?('mosql_tailers') do
column :service, 'TEXT'
column :timestamp, 'INTEGER'
primary_key [:service]
end
new_info = info.dup
# new_info[:timestamp] = 1409262430
new_info.delete(:placeholder)
tailer_db = sql[:mosql_tailers]
tailer_db.insert(new_info)
# verify
tailer_db.all()
```

After restarting mosql, the blog_posts table should still be empty, but the tailers table should have an extra column filled with the new info