# couchpenter

> CouchDB database and document setup tool.

Latest version **0.3.0** (published 2015-06-21) · 0 weekly downloads

## Install

```sh
npm install couchpenter
pnpm add couchpenter
yarn add couchpenter
bun add couchpenter
```

Provides the command `couchpenter`.

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2015-06-21 |
| First published | 2012-03-22 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Cliffano Subagio |
| Maintainers | cliffano |
| Keywords | couchdb, nosql, database, cli |

## Links

- npm: https://www.npmjs.com/package/couchpenter
- Repository: http://github.com/cliffano/couchpenter
- Issues: http://github.com/cliffano/couchpenter/issues
- npm.io page: https://npm.io/package/couchpenter

## Dependencies (8)

- [cron](https://npm.io/package/cron.md) ^1.0.9
- [nano](https://npm.io/package/nano.md) ^6.1.3
- [async](https://npm.io/package/async.md) ^1.2.1
- [clone](https://npm.io/package/clone.md) ^1.0.2
- [lodash](https://npm.io/package/lodash.md) ^3.9.3
- [bagofcli](https://npm.io/package/bagofcli.md) ^0.2.2
- [fs.extra](https://npm.io/package/fs.extra.md) ^1.3.2
- [bagofrequest](https://npm.io/package/bagofrequest.md) ^0.1.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2015-06-21
- 0.2.4 — 2013-06-11
- 0.2.3 — 2013-04-03
- 0.2.2 — 2013-02-27
- 0.2.1 — 2013-02-12
- 0.2.0 — 2013-02-04
- 0.1.3 — 2012-10-12
- 0.1.2 — 2012-09-24
- 0.1.1 — 2012-09-16
- 0.1.0 — 2012-09-12
- 0.0.8 — 2012-09-12
- 0.0.7 — 2012-04-18
- 0.0.6 — 2012-04-07
- 0.0.5 — 2012-04-07
- 0.0.4 — 2012-03-26
- … 3 more at https://npm.io/package/couchpenter/versions

## README

<img align="right" src="https://raw.github.com/cliffano/couchpenter/master/avatar.jpg" alt="Avatar"/>

[![Build Status](https://img.shields.io/travis/cliffano/couchpenter.svg)](http://travis-ci.org/cliffano/couchpenter)
[![Dependencies Status](https://img.shields.io/david/cliffano/couchpenter.svg)](http://david-dm.org/cliffano/couchpenter)
[![Coverage Status](https://img.shields.io/coveralls/cliffano/couchpenter.svg)](https://coveralls.io/r/cliffano/couchpenter?branch=master)
[![Published Version](https://img.shields.io/npm/v/couchpenter.svg)](http://www.npmjs.com/package/couchpenter)
<br/>
[![npm Badge](https://nodei.co/npm/couchpenter.png)](http://npmjs.org/package/couchpenter)

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@host:port

CouchDB URL can also be set via COUCHDB_URL environment variable:

(*nix)

    export COUCHDB_URL=http://user:pass@host:port

(Windows)

    set COUCHDB_URL=http://user:pass@host:port

Execute a task using custom setup file:

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

Tasks:

<table>
<tr><th>Task</th><th>Description</th></tr>
<tr><td>setup</td><td>Create databases and documents, overwrite if documents exist.</td></tr>
<tr><td>setup-db</td><td>Create databases only.</td></tr>
<tr><td>setup-doc</td><td> Create documents only, does not overwrite if exist.</td></tr>
<tr><td>setup-doc-overwrite</td><td>Create documents only, overwrite if exist.</td></tr>
<tr><td>teardown</td><td>Alias for teardown-db.</td></tr>
<tr><td>teardown-db</td><td>Delete databases.</td></tr>
<tr><td>teardown-doc</td><td>Delete documents.</td></tr>
<tr><td>reset</td><td>Alias for reset-doc.</td></tr>
<tr><td>reset-db</td><td>Delete then recreate databases and documents.</td></tr>
<tr><td>reset-doc</td><td>Delete then recreate documents only.</td></tr>
<tr><td>clean</td><td>Alias for clean-db.</td></tr>
<tr><td>clean-db</td><td>Delete unknown databases (not configured in setup file).</td></tr>
<tr><td>warm-view</td><td>Warm up views specified in design documents.</td></tr>
</table>

Programmatically:

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

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

    // use setup object (instead of setup file)
    var couchpenter = new (require('couchpenter'))(
      'http://user:pass@host:port',
      { dbSetup: {
          "db1": [
            { "_id": "doc1", "foo": "bar" },
            { "_id": "doc2", "foo": "bar" },
            "path/to/doc3file.json"
          ]
        }
      }
    );

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

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

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

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

    // delete databases and documents, then set up databases and documents
    couchpenter.reset(function (err, results) {
    });

    // delete documents, then set up documents
    couchpenter.resetDocuments(function (err, results) {
    });

    // warm up all views specified in design documents
    couchpenter.warmViews(function (err, results) {
    });

    // warm up all views specified in design documents every minute (scheduled)
    couchpenter.warmViews('* * * * *', function (err, results) {
    });

Check out [lib/couchpenter](https://github.com/cliffano/couchpenter/blob/master/lib/couchpenter.js) for other available methods.

Configuration
-------------

Couchpenter setup file is just a simple JSON file:

    {
      "db1": [
        { "_id": "doc1", "foo": "bar" },
        { "_id": "doc2", "foo": "bar" },
        "path/to/doc3file.json"
      ],
      "db2": [
        { "_id": "doc4", "foo": "bar" },
        "path/to/modulename"
      ],
      "db3": [],
      "_replicator": {
        {
          "_id": "db1_pull",
          "source": "http://user:pass@remotehost:5984/db1",
          "target": "db1",
          "user_ctx": {
            "name": "user",
            "roles": ["_admin"]
          },
          "continuous": true
        }
      }
    }

Property keys are the names of the databases, property values are the documents in each database.

A document can be represented as:

* an object
* a file path string containing a JSON document, file name must end with .json
* a module path string

Paths are relative to current directory if it's used from command-line, or relative to opts.dir if it's used programmatically (defaults to current directory if opts.dir is not specified).

Colophon
--------

[Developer's Guide](http://cliffano.github.io/developers_guide.html#nodejs)

Build reports:

* [Code complexity report](http://cliffano.github.io/couchpenter/complexity/plato/index.html)
* [Unit tests report](http://cliffano.github.io/couchpenter/test/buster.out)
* [Test coverage report](http://cliffano.github.io/couchpenter/coverage/buster-istanbul/lcov-report/lib/index.html)
* [Integration tests report](http://cliffano.github.io/couchpenter/test-integration/cmdt.out)
* [API Documentation](http://cliffano.github.io/couchpenter/doc/dox-foundation/index.html)

Related Projects:

* [couchtato](http://github.com/cliffano/couchtato) - CouchDB documents iterator tool

---
_Source: https://npm.io/package/couchpenter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
