source: Dev/trunk/src/server/config/upgrade-couchdb.js @ 534

Last change on this file since 534 was 526, checked in by hendrikvanantwerpen, 11 years ago

Removed q leftover.

File size: 1.2 KB
Line 
1var HTTPResult = require('../util/http-result')
2  , _ = require('underscore')
3  , CouchDB = require('../util/couch')
4  ;
5
6var schema = require('./couchdb-schema');
7
8module.exports = function(couchServerURL,dbName,upgrade) {
9    var server = new CouchDB(couchServerURL,dbName);
10    var designRe = /^_design\//;
11    return server.get('/_all_docs')
12    .then(function(allDocs){
13        return _.chain(allDocs.rows)
14        .filter(function(doc){
15            return doc.id.match(designRe) === null;
16        })
17        .reduce(function(memo, doc){
18            return memo.then(function(result){
19                return server.get(doc.id)
20                .then(function(doc){
21                    HTTPResult.when(200,upgrade(doc))
22                    .then(function(newDoc){
23                        return server.put(doc._id,newDoc)
24                        .then(function(){
25                            result[doc._id] = true;
26                            return result;
27                        });
28                    },function(){
29                        result[doc._id] = false;
30                    });
31                    return result;
32                });
33            });
34        }, new HTTPResult(200,{}))
35        .value();
36    });
37};
Note: See TracBrowser for help on using the repository browser.