database replication methods, no conflict resolution provided
This commit is contained in:
parent
e9f7456eab
commit
571cd257e0
|
@ -214,6 +214,18 @@ module CouchRest
|
|||
CouchRest.post "#{@root}/_compact"
|
||||
end
|
||||
|
||||
# Replicates via "pulling" from another database to this database. Makes no attempt to deal with conflicts.
|
||||
def replicate_from other_db
|
||||
raise ArgumentError, "must provide a CouchReset::Database" unless other_db.kind_of?(CouchRest::Database)
|
||||
CouchRest.post "#{@host}/_replicate", :source => other_db.root, :target => name
|
||||
end
|
||||
|
||||
# Replicates via "pushing" to another database. Makes no attempt to deal with conflicts.
|
||||
def replicate_to other_db
|
||||
raise ArgumentError, "must provide a CouchReset::Database" unless other_db.kind_of?(CouchRest::Database)
|
||||
CouchRest.post "#{@host}/_replicate", :target => other_db.root, :source => name
|
||||
end
|
||||
|
||||
# DELETE the database itself. This is not undoable and could be rather
|
||||
# catastrophic. Use with care!
|
||||
def delete!
|
||||
|
|
|
@ -625,5 +625,36 @@ describe CouchRest::Database do
|
|||
end
|
||||
end
|
||||
|
||||
describe "replicating a database" do
|
||||
before do
|
||||
@db.save({'_id' => 'test_doc', 'some-value' => 'foo'})
|
||||
@other_db = @cr.database 'couchrest-test-replication'
|
||||
@other_db.delete! rescue nil
|
||||
@other_db = @cr.create_db 'couchrest-test-replication'
|
||||
end
|
||||
|
||||
describe "via pulling" do
|
||||
before do
|
||||
@other_db.replicate_from @db
|
||||
end
|
||||
|
||||
it "contains the document from the original database" do
|
||||
doc = @other_db.get('test_doc')
|
||||
doc['some-value'].should == 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
describe "via pushing" do
|
||||
before do
|
||||
@db.replicate_to @other_db
|
||||
end
|
||||
|
||||
it "copies the document to the other database" do
|
||||
doc = @other_db.get('test_doc')
|
||||
doc['some-value'].should == 'foo'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue