views:

286

answers:

2

I'm considering using CouchDB for an upcoming web development project.

What is the best way to keep the CouchDB document repo in sync between various developers who are all running the application locally?

An Example: Suppose Developer A creates a new view or design document in Couch or just simply adds a field to an existing view. They also check in some client-side code that expects that field to be on the CouchDB view. Developer B comes in and updates to the latest source code, pulling down Developer A's client-side changes. How does Developer B get the Couch changes that accompany the client-side code?

In a typical RDBMS, this would be accomplished by checking a set of SQL files or database migrations into the SCM system. After Developer B updates his code he would run the new SQL or migration scripts to upgrade his database schema.

Perhaps in Couch there is a way to export/import design docs and view definitions and check those into an SCM system? Perhaps I just need my RDBMS background brainwashing to be deprogrammed.

+3  A: 

I've typically kept .js files of my views' map and reduce functions, and stored those in my code repository. A common pattern is to have a folder for each view, and a separate .js file for each view function (map/reduce). An example:

views/
    tags/
        map.js
        reduce.js
    users/
        map.js
        reduce.js

The content of views/tags/map.js is simply the JavaScript map function, for example:

function(doc) {
    if(doc.tags && doc.tags.length) {
        for(var index in doc.tags) {
            emit(doc.tags[index], null);
        }
    }
}

You can then manage your views any way you choose, possibly using CouchApp or something like it to sync everything to a CouchDB instance. Of course, I don't know what the "best practice" is, but this is what I've done and it works well with my team.

Ryan Duffield
A: 

Ryan's suggestions above is a good one. DB::CouchDB::Schema is a perl library that has a script bundled that can export and import your design documents. It might help automate the job for you.

Jeremy Wall