From 9e4d5c0edaa22ad55b62a5d5ba3e8579202f95fd Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 13 Sep 2008 18:59:24 -0400 Subject: [PATCH] backwards compatibility for old couchdbs --- lib/couchrest/core/database.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/couchrest/core/database.rb b/lib/couchrest/core/database.rb index 90c99f5..aea133f 100644 --- a/lib/couchrest/core/database.rb +++ b/lib/couchrest/core/database.rb @@ -64,17 +64,23 @@ module CouchRest end if doc['_id'] slug = CGI.escape(doc['_id']) + CouchRest.put "#{@root}/#{slug}", doc else - slug = doc['_id'] = @server.next_uuid + begin + slug = doc['_id'] = @server.next_uuid + CouchRest.put "#{@root}/#{slug}", doc + rescue #old version of couchdb + CouchRest.post @root, doc + end end - CouchRest.put "#{@root}/#{slug}", doc end def bulk_save docs ids, noids = docs.partition{|d|d['_id']} uuid_count = [noids.length, @server.uuid_batch_count].max noids.each do |doc| - doc['_id'] = @server.next_uuid(uuid_count) + nextid = @server.next_uuid(uuid_count) rescue nil + doc['_id'] = nextid if nextid end CouchRest.post "#{@root}/_bulk_docs", {:docs => docs} end