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

Last change on this file since 513 was 492, checked in by hendrikvanantwerpen, 11 years ago
  • Enable/disable buttons on content change.
  • One place to do date formatting, because it was going wrong again.
  • Serialize questions in survey properly.
  • _ComplexValueMixin consumes submit events, but does trigger outer forms if present.
  • Trigger dialog show/hide for login only after previous effect is finished.
  • Check that documents are actually valid, not just that validator returned a result.
  • Validate email and timestamp formats.
  • Prepared for live runs.
File size: 1.2 KB
Line 
1var Q = require('q')
2  , _ = require('underscore')
3  , CouchDB = require('../util/couch').CouchDB
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                    Q.when(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        }, Q.resolve({}))
35        .value();
36    }).all();
37};
Note: See TracBrowser for help on using the repository browser.