{"id":15595441,"url":"https://github.com/cdimascio/couchinator","last_synced_at":"2025-04-24T06:33:35.208Z","repository":{"id":52059943,"uuid":"81228434","full_name":"cdimascio/couchinator","owner":"cdimascio","description":"🛋️ Fixtures for CouchDB and IBM Cloudant: Create and teardown cloudant dbs","archived":false,"fork":false,"pushed_at":"2022-12-08T05:00:15.000Z","size":3574,"stargazers_count":5,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T04:38:03.421Z","etag":null,"topics":["bluemix","cli","cloudant","couchdb","database","fixture-loader","fixtures","ibm-cloudant","test-automation","test-driven-development"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdimascio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-07T16:21:32.000Z","updated_at":"2021-02-23T23:31:22.000Z","dependencies_parsed_at":"2023-01-24T11:30:14.216Z","dependency_job_id":null,"html_url":"https://github.com/cdimascio/couchinator","commit_stats":null,"previous_names":["cdimascio/cloudant-database-generator"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcouchinator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcouchinator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcouchinator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdimascio%2Fcouchinator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdimascio","download_url":"https://codeload.github.com/cdimascio/couchinator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250579380,"owners_count":21453467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bluemix","cli","cloudant","couchdb","database","fixture-loader","fixtures","ibm-cloudant","test-automation","test-driven-development"],"created_at":"2024-10-03T01:00:22.153Z","updated_at":"2025-04-24T06:33:35.178Z","avatar_url":"https://github.com/cdimascio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# couchinator\n\n![](https://img.shields.io/badge/status-stable-green.svg) ![](https://img.shields.io/npm/v/couchinator.svg) ![](https://img.shields.io/badge/license-Apache2.0-blue.svg)\n\nFixtures for [CouchDB](http://couchdb.apache.org/) and [IBM Cloudant](https://www.ibm.com/cloud/cloudant).\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"https://github.com/cdimascio/couchinator/raw/master/assets/couchinator.png\" width=\"650\"/\u003e\n\u003c/p\u003e\n\nSetup and teardown CouchDB and IBM Cloudant databases with ease. **couchinator** is a great tool for unit/integration testing and more. couchinator is both a library and a command line utility. \n\n## See it in action\n\nRepresent your database(s) as a set of folders and files and couchinator takes care of the rest.\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"https://github.com/cdimascio/couchinator/raw/master/assets/couchinator-anim.gif\"/\u003e\n\u003c/p\u003e\n\nSee the [Data Layout](#data-layout) section for information on how to represent your database with couchinator.\n\n## Install\n\n```shell\nnpm install couchinator\n```\n\nGlobal installation is convenient when using the **CLI**\n\n```shell\nnpm install couchinator -g\n```\n\nIf you're a Java user, try [this](https://github.com/cdimascio/couchinator-java-wrapper)\n\n## Use the CLI\n\n```shell\ncouchinator create --url http://127.0.0.1:5984 --path ./fixtures\n```\n\n#### Create\n\n```shell\ncouchinator create --url \u003cCOUCHDB-OR-CLOUDANT-URL\u003e --path \u003cRESOURCE_PATH\u003e\n```\n\n#### Destroy\n\n```shell\ncouchinator destroy --url \u003cCOUCHDB-OR-CLOUDANT-URL\u003e --path \u003cRESOURCE_PATH\u003e\u003cbr\u003e\n```\n\n#### Recreate\n\n```shell\ncouchinator recreate --url \u003cCOUCHDB-OR-CLOUDANT-URL\u003e --path \u003cRESOURCE_PATH\u003e\n```\n\n**Note:** `RESOURCE_PATH` may be absolute path or a path relative to the current working directy\n\n## Use the Library\n\n#### Basic Usage\n\n```javascript\nconst Couchinator = require('couchinator');\n\nconst couchinator = new Couchinator('http://127.0.0.1:5984').resources(\n  './fixtures'\n);\n\n// Each of the following methods return a promise\ncouchinator.create();\ncouchinator.recreate();\ncouchinator.destroy();\n```\n\nsee [Advanced Usage](#advanced-usage) for more library customization options\n\n## Data Layout\n\nThe following sections describe how to create a data layout.\n\nTo skip directly to a working example, go [here](examples/db-resources)\n\n### Getting Started\n\nCouchinator enables you to represent CouchDB and Cloudant database(s) using a simple filesystem structure that mimics the actual database structure.\n\nA couchinator filesystem data layout might look as such:\n\n```shell\nusers\n    _design\n        students.json\n\t teachers.json\n    students-docs.json\n    teachers-docs.json\nclassrooms\n    _design\n        classrooms.json\n        classrooms-docs.json\n```\n\n### Create a data layout representing 2 databases\n\nLet's create a data layout to describe two databases **users** and **classrooms**\n\n1.  **Create two folders, one for `users` and another for `classrooms`.**\n\n    ```shell\n    users/\n    classrooms/\n    ```\n\n    **Note:** Couchinator will use the folder name as the database name\n\n2.  **Within each folder _optionally_ create a `_design` folder to store any design documents**\n\n    ```shell\n    users/\n        _design/\n    classrooms/\n        _design/\n    ```\n\n3.  **Create design document(s) and store them in the appropriate `_design` folder**\n\n    In the example below, we create two design documents in the `schools` database and one in the `users` database.\n\n    ```shell\n    users/\n        _design/\n            students.json\n            teachers.json\n    classrooms/\n        _design/\n            classrooms.json\n    ```\n\n    The contents of each design document `.json` must be a valid CouchDB [design document](http://docs.couchdb.org/en/2.0.0/json-structure.html#design-document).\n\n    For example, `students.json`:\n\n    ```json\n    {\n      \"_id\": \"_design/students\",\n      \"views\": {\n        \"byId\": {\n          \"map\": \"function (doc) {  if (doc.type === 'student') emit(doc._id, doc);}\"\n        }\n      },\n      \"language\": \"javascript\"\n    }\n    ```\n\n4.  **Create the data to store in each database**\n\n    - Data must be represented using CouchDB's [bulk document](http://docs.couchdb.org/en/2.0.0/json-structure.html#bulk-documents) format\n    - The data may be represented in a _single_ JSON file or spread across _multiple_ JSON files (useful for organizing data)\n\n    ```shell\n    users/\n        _design/\n            students.json\n            teachers.json\n        students-docs.json   # contains student data\n        teachers-docs.json   # contains teacher data\n\n    classrooms/\n        _design/\n            classrooms.json\n        users-docs.json\n    ```\n\n    For example, `student-docs.json` contains students\n\n    ```json\n    {\n      \"docs\": [\n        {\n           \"_id\": \"sam895454857\",\n           \"name\": \"Sam C.\",\n           \"type\": \"student\"\n         },\n         {\n           \"_id\": \"josie895454856\",\n           \"name\": \"Josie D.\",\n           \"type\": \"student\"\n         }\n       ]\n    }\n    ```\n\n5. **Run couchinator to create each database**\n\n   Assuming the data layout is stored in the folder `./fixtures`, run the following command(s):\n\n   ```shell\n   couchinator create --url http://127.0.0.1:5984 --path ./fixtures\n   ```\n\n## Data Layout Example\n\nTo view a complete data layout example, see [examples/db-resources](examples/db-resources).\n\nTo run the the example:\n\n- clone this repo\n- `cd examples`\n- edit examples.js and set `\u003cCLOUDANT-URL\u003e` to your cloudant url\n- Run `node example`\n- Your database should now contain documents\n\n## Library Initialization\n\nvar cloudant = Cloudant({account:me, password:password});\nIf you would prefer, you can also initialize Cloudant with a URL:\n\n#### Cloudant Url\n\n```javascript\nconst url = 'https://MYUSERNAME:MYPASSWORD@MYACCOUNT.cloudant.com';\nnew Couchinator(url);\n```\n\n#### Account\n\n```javascript\nconst url = 'https://MYUSERNAME:MYPASSWORD@MYACCOUNT.cloudant.com';\nnew Couchinator({ account: me, password: password });\n```\n\n### Advanced Usage\n\nThe couchinator library enables a variety of customizations, including the ability to provide a custom visitor to configure exactly what log information is output.\n\n```javascript\nconst Generator = require('couchinator');\nconst path = require('path');\n\n// Define the directory that contains our db resources\nconst resourcePath = path.join(process.cwd(), 'db-resources');\n\nconst c = new Couchinator('\u003cYOUR-DB-URL\u003e')\n  .resources(resourcePath)\n  .visitor(e =\u003e {\n  \t\tif (e.level \u003e= 30) console.log(e.msg);\n\t})\n  .configure();\n```\n\n## Apis\n\n- **`couchinator create`**\n\n  Creates all databases, design documents, and executes any bulk documents represented in the [data layout](#data-layout). If a design document exists, the design document is updated to reflect the version currently represented in the [data layout](#data-layout).\n\n  Using the `--ddocsonly` flag skips any bulk documents. This flag is particulary useful when you simply want to add/update design documents.\n\n- **`couchinator destroy`**\n\n  destroys all databases represented in the [data layout](#data-layout).\n\n- **`couchinator rcreate`**\n  Calls destroy followed by create.\n\nSee [CLI Usage](#cli-usage) section for additional arguments.\n\n## CLI Usage\n\nCurrently, the CLI only support a Cloudant URL.\n\n```shell\n\u003e couchinator\n  Usage: couchinator [options] [command]\n\n\n  Commands:\n\n    create\n    recreate\n    destroy\n\n  Options:\n\n    -h, --help        output usage information\n    -V, --version     output the version number\n    -u --url \u003curl\u003e    couchdb url\n    -p --path \u003cpath\u003e  resource path. Default ./fixtures\n    -b --verbose      verbose logs\n    -d --ddocsonly    import design docs only. Do no import other docs\n```\n\n## TODO / Errata\n\n- if design doc name doesnt match its file name, we get a null crash\n\n## License\n\n[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdimascio%2Fcouchinator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdimascio%2Fcouchinator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdimascio%2Fcouchinator/lists"}