<commit_before>Couchpenter [![http://travis-ci.org/cliffano/couchpenter](https://secure.travis-ci.org/cliffano/couchpenter.png?branch=master)](http://travis-ci.org/cliffano/couchpenter)
-----------

Couchpenter is a CouchDB database and document setup tool.

This is handy when you want to create or delete CouchDB databases and documents based on a predefined setup file, either from the command-line or programmatically.

A common usage scenario is to hook up Couchpenter to application start up code, ensuring CouchDB to have the required databases along with any data, design, and replication documents, before the server starts listening.

Another usage is for integration testing, either from test libraries (e.g. Mocha's beforeEach/afterEach), or from a Continuous Integration build pipeline (e.g. resetting the databases prior to running the test suites).

Installation
------------

    npm install -g couchpenter 

Usage
-----

Create a sample couchpenter.json setup file:

    couchpenter init

Execute a task against a CouchDB URL using default couchpenter.json setup file:

    couchpenter <task> -u http://user:pass@localhost:5984

Execute a task using custom setup file:

    couchpenter <task> -u http://user:pass@localhost:5984 -f somecouchpenter.json

Tasks:

<table>
<tr><th>Task</th><th>Description</th></tr>
<tr><td>setup</td><td>Create databases, then create/update documents.</td></tr>
<tr><td>setup-db</td><td>Create databases only.</td></tr>
<tr><td>setup-doc</td><td>Create documents only.</td></tr>
<tr><td>teardown</td><td>Delete databases, including documents.</td></tr>
<tr><td>teardown-db</td><td>Alias for teardown</td></tr>
<tr><td>teardown-doc</td><td>Delete documents only.</td></tr>
<tr><td>reset</td><td>Delete then recreate databases and documents.</td></tr>
<tr><td>reset-db</td><td>Alias for reset</td></tr>
<tr><td>reset-doc</td><td>Delete then recreate documents only.</td></tr>
</table>

Programmatically:

    // use default couchpenter.json setup file
    var couchpenter = new require('couchpenter').Couchpenter(
      'http://user:pass@localhost:5984'
    );

    // use custom setup file
    var couchpenter = new require('couchpenter').Couchpenter(
      'http://user:pass@localhost:5984',
      { setupFile: 'somecouchpenter.json' }
    );

    // prefix the database names
    // handy for running multiple tests in parallel without interrupting each other
    var couchpenter = new require('couchpenter').Couchpenter(
      'http://user:pass@localhost:5984',
      { prefix: 'testrun123_' }
    );

    // specify a base directory for the documents specified in setup file
    var couchpenter = new require('couchpenter').Couchpenter(
      'http://user:pass@localhost:5984',
      { dir: '../some/dir/' }
    );

    // set up databases and documents
    couchpenter.setUp(function (err, result) {
    });

    // delete databases and documents
    couchpenter.tearDown(function (err, result) {
    });

    // delete databases and documents, then set up databases and documents
    couchpenter.reset(function (err, result) {<commit_msg>Fix sample usage documentation based on  >= v0.0.8 . #2<commit_after>Couchpenter [![http://travis-ci.org/cliffano/couchpenter](https://secure.travis-ci.org/cliffano/couchpenter.png?branch=master)](http://travis-ci.org/cliffano/couchpenter)
-----------

Couchpenter is a CouchDB database and document setup tool.

This is handy when you want to create or delete CouchDB databases and documents based on a predefined setup file, either from the command-line or programmatically.

A common usage scenario is to hook up Couchpenter to application start up code, ensuring CouchDB to have the required databases along with any data, design, and replication documents, before the server starts listening.

Another usage is for integration testing, either from test libraries (e.g. Mocha's beforeEach/afterEach), or from a Continuous Integration build pipeline (e.g. resetting the databases prior to running the test suites).

Installation
------------

    npm install -g couchpenter 

Usage
-----

Create a sample couchpenter.json setup file:

    couchpenter init

Execute a task against a CouchDB URL using default couchpenter.json setup file:

    couchpenter <task> -u http://user:pass@localhost:5984

Execute a task using custom setup file:

    couchpenter <task> -u http://user:pass@localhost:5984 -f somecouchpenter.json

Tasks:

<table>
<tr><th>Task</th><th>Description</th></tr>
<tr><td>setup</td><td>Create databases, then create/update documents.</td></tr>
<tr><td>setup-db</td><td>Create databases only.</td></tr>
<tr><td>setup-doc</td><td>Create documents only.</td></tr>
<tr><td>teardown</td><td>Delete databases, including documents.</td></tr>
<tr><td>teardown-db</td><td>Alias for teardown</td></tr>
<tr><td>teardown-doc</td><td>Delete documents only.</td></tr>
<tr><td>reset</td><td>Delete then recreate databases and documents.</td></tr>
<tr><td>reset-db</td><td>Alias for reset</td></tr>
<tr><td>reset-doc</td><td>Delete then recreate documents only.</td></tr>
</table>

Programmatically:

    // use default couchpenter.json setup file
    var couchpenter = new (require('couchpenter'))(
      'http://user:pass@localhost:5984'
    );

    // use custom setup file
    var couchpenter = new (require('couchpenter'))(
      'http://user:pass@localhost:5984',
      { setupFile: 'somecouchpenter.json' }
    );

    // prefix the database names
    // handy for running multiple tests in parallel without interrupting each other
    var couchpenter = new (require('couchpenter'))(
      'http://user:pass@localhost:5984',
      { prefix: 'testrun123_' }
    );

    // specify a base directory for the documents specified in setup file
    var couchpenter = new (require('couchpenter'))(
      'http://user:pass@localhost:5984',
      { dir: '../some/dir/' }
    );

    // set up databases and documents
    couchpenter.setUp(function (err, result) {
    });

    // delete databases and documents
    couchpenter.tearDown(function (err, result) {
    });

    // delete databases and documents, then set up databases and documents
    couchpenter.reset(function (err, result) {
{'fraction_non_alphanumeric': 0.13749595600129408, 'fraction_numerical': 0.009382076997735361, 'mean_word_length': 3.9464, 'pattern_counts': {'":': 0, '<': 131, '<?xml version=': 0, '>': 132, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2030647', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1858, 'n_words': 553}