Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Bootstrap CouchDB server from CLI or API.
* create and update design documents
* create and update replication documents
* create and update seed documents
* create indexes

CouchDB Bootstrap combines different small tools, which can also be used
independently. Each of those tools come has a similar API and is shipped with a
Expand All @@ -17,6 +18,7 @@ CLI:
* [couchdb-ensure](https://github.com/jo/couchdb-ensure) - Create database unless exists
* [couchdb-push](https://github.com/jo/couchdb-push) - Push documents: users, replications, design docs and normal documents
* [couchdb-secure](https://github.com/jo/couchdb-secure) - Secure databases: write security object
* [couchdb-create-index](https://github.com/jo/couchdb-create-index) - Add Mango indexes

## Directory

Expand All @@ -36,6 +38,7 @@ project/couchdb
│   ├── _design
│   │   └── myapp.js
│   ├── _security.json
│   ├── _index.json
│   └── adoc.json
├── myapp-alice
│   ├── doc1.json
Expand Down Expand Up @@ -76,6 +79,13 @@ Since couchdb-bootstrap@14.2 it is possible to provide a configuration object:
date: '2018-03-16T19:27:52.361Z',
title: 'Welcome'
},
_index: {
index: {
fields: ['date']
},
name: 'by-date',
type: 'json'
},
_design: {
myapp: {
views: {
Expand Down
23 changes: 23 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const assert = require('assert')
const compile = require('couchdb-compile')
const couchdbConfigure = require('couchdb-configure')
const couchdbSecure = require('couchdb-secure')
const couchdbCreateIndex = require('couchdb-create-index')
const couchdbPush = require('couchdb-push')

const DOCS_REGEX = /^(_design|_local|[^_].*)$/
Expand Down Expand Up @@ -94,13 +95,35 @@ module.exports = function (url, source, options, callback) {
}
}

const dbsWithIndex = dbs.filter(dbname => '_index' in source[dbname])
if (dbsWithIndex.length) {
series.index = done => {
couch.request({
path: ''
}, (error, info) => {
if (error) { return done(error) }
if (info.version < 2) {
return done(error, { index: 'not supported by couchdb version ' + info.version })
}

async.map(dbsWithIndex, (dbname, next) => {
const db = mapDbName(options, dbname)
couchdbCreateIndex(couch.use(db), source[dbname]._index, groupByDatabase(db, next))
}, reduceGroupedResult(done))
})
}
}

const dbsWithDocs = dbs.filter(dbname => Object.keys(source[dbname]).filter(isDoc).length)
if (dbsWithDocs.length) {
series.push = done => {
async.map(dbsWithDocs, (dbname, next) => {
const docs = Object.keys(source[dbname])
.filter(isDoc)
.reduce((memo, id) => {
if (id === '_security') return memo
if (id === '_index') return memo

let docs = []

if (id === '_local') {
Expand Down
Loading