Skip to content

Commit 40467dc

Browse files
committed
feat: integrate couchdb-create-index
1 parent 17d7683 commit 40467dc

File tree

7 files changed

+171
-12744
lines changed

7 files changed

+171
-12744
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bootstrap CouchDB server from CLI or API.
88
* create and update design documents
99
* create and update replication documents
1010
* create and update seed documents
11+
* create indexes
1112

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

2123
## Directory
2224

@@ -36,6 +38,7 @@ project/couchdb
3638
│   ├── _design
3739
│   │   └── myapp.js
3840
│   ├── _security.json
41+
│   ├── _index.json
3942
│   └── adoc.json
4043
├── myapp-alice
4144
│   ├── doc1.json
@@ -76,6 +79,13 @@ Since [email protected] it is possible to provide a configuration object:
7679
date: '2018-03-16T19:27:52.361Z',
7780
title: 'Welcome'
7881
},
82+
_index: {
83+
index: {
84+
fields: ['date']
85+
},
86+
name: 'by-date',
87+
type: 'json'
88+
},
7989
_design: {
8090
myapp: {
8191
views: {

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const assert = require('assert')
66
const compile = require('couchdb-compile')
77
const couchdbConfigure = require('couchdb-configure')
88
const couchdbSecure = require('couchdb-secure')
9+
const couchdbCreateIndex = require('couchdb-create-index')
910
const couchdbPush = require('couchdb-push')
1011

1112
const DOCS_REGEX = /^(_design|_local|[^_].*)$/
@@ -94,6 +95,16 @@ module.exports = function (url, source, options, callback) {
9495
}
9596
}
9697

98+
const dbsWithIndex = dbs.filter(dbname => '_index' in source[dbname])
99+
if (dbsWithIndex.length) {
100+
series.index = done => {
101+
async.map(dbsWithIndex, (dbname, next) => {
102+
const db = mapDbName(options, dbname)
103+
couchdbCreateIndex(couch.use(db), source[dbname]._index, groupByDatabase(db, next))
104+
}, reduceGroupedResult(done))
105+
}
106+
}
107+
97108
const dbsWithDocs = dbs.filter(dbname => Object.keys(source[dbname]).filter(isDoc).length)
98109
if (dbsWithDocs.length) {
99110
series.push = done => {

0 commit comments

Comments
 (0)