简体   繁体   中英

couchDB designDoc development workflow and version control

For development, I want to keep the various components ( views , lists , shows ) that make up a couchDB design document as separate files alongside my other development code in a dir called couchDB for example. When I am happy with changes I want to use couchapp.push to send to database, whilst also being able to version control the design doc component files.

I'm thinking maybe using the node module 'couchapp' and node to scan a directory and its sub-dirs for .js files then using them to construct the design docs and upload to couchDB. Perhaps with sub dirs structured like so:

designDocsJs
  |-- views
  |     |--view1.js
  |     |--view2.js
  |-- shows
  |-- lists

Is it possible to put map and reduce in the same file eg. 'view1.js' or would they need to be in separate files 'view1-map.js' and 'view1-reduce.js' ?

Curretnly I am using the following, but I am not sure how to go about reading the .js files using node and dynamically adding them to the ddoc.views{} ? Any guidance would be appreciated, particularly with a javascript/node solution.

var couchapp = require('couchapp')
    , path = require('path');

  ddoc = {
      _id: '_design/entitiesNew'
    , views: {}
    , lists: {}
    , shows: {} 
  }

  // node module exports
  module.exports = ddoc;

  // REPLACE ME WITH SOME WAY OF READING A
  // STRUCTURED DIR OF .JS FILES AND COMBINING
  // AS NECESSARY
  ddoc.views.byType = {
    map: function(doc) {
      emit(doc.type, null);
    },
    reduce: '_count'
  }

  couchapp.loadAttachments(ddoc, path.join(__dirname, '_attachments'));

and then:

$ cd path/to/here
$ mkdir _attachments
$ couchapp push updateCouchDbDesigndocs.js http://localhost:5984/databaseName

The couchapp tool does just this. I push using couchapp and no other scripts.

Here is the directory structure:

mycouchappdir
|-- views/
    |-- myview1/
       |-- map.js
       |-- reduce.js
|-- shows/
    |-- myshow1.js
    |-- myshow2.js
|-- _attachments/
    |-- myattachment.png

Your map.js file will look like the following:

function(doc) {
   emit(doc.type, null);
}

Then just run couchapp push from the mycouchappdir .


You may also wish to consider putting your couchapps in their own repositories. Running couchapp push always creates a new revision to the design document. So if you have a different repository for your couchapp then when you make a change to the repository it is a change to the couchapp and you can push it knowing that the new revision is different than the old.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM