In a NoSQL DB you probably have no schema. I will not argue here about structured/semistructured/unstructured choices. That is a subject for a bigger discussion for which my simple answer is "- it depends". But I will argue here that your Views in CouchDB or whatever you call the map/reduce functions in your favorite noSQL must be kept in a version control repository.
I will also argue that any migrations applied to Views should automatically generate the latest version of them and should be committed to your version control system.
I should not have to say it but all of the above should be automated for sure.
To use the design document later on in couchDB you need to PUT it in the couchdb server database, however the "_rev" attribute must be removed first. Again nothing Unix Power Tools won't be able to do. Here is how to do a correct backup:
#extract design document from db curl -ksX GET "https://user:email@example.com:6984/mydb/_design/EmailDocument" | python -mjson.tool | sed '/\"_rev\"/d' > mydb-couchdb-design-Document.jsonHere is how you would put the design document back into a couchdb database (restore). Note how we need the revision to be able to delete and then after deleted we just PUT our saved copy. We can probably do the same with just one POST instead of DELETE+PUT but you get the idea about the power of unix tools here.
$ revision=`curl -ksX GET "https://user:firstname.lastname@example.org:6984/mydb/_design/MyDocument" | sed 's/.*_rev\":\"\([^\"]*\).*/\1/g'` $ curl -ksX DELETE "https://user:email@example.com:6984/mydb/_design/MyDocument?rev=$revision" $ curl -ksX PUT "https://user:firstname.lastname@example.org:6984/mydb/_design/MyDocument" --data-binary @mydb-couchdb-design-Document.jsonNow you can keep your views in version control and should you need a blank database it is just a matter of creating it and running the previous code to create the views:
#extract design document from db curl -ksX GET "https://user:email@example.com:6984/mydb/_design/EmailDocument" | python -mjson.tool | sed '/\"_rev\"/d' > mydb-couchdb-design-Document.json #delete database curl -ksX DELETE "https://user:firstname.lastname@example.org:6984/mydb" #create database curl -ksX PUT "https://user:email@example.com:6984/mydb" #put the design document in db 630 curl -ksX PUT "https://user:firstname.lastname@example.org:6984/mydb/_design/MyDocument" --data-binary @mydb-couchdb-design-Document.json