Skip to content

Commit

Permalink
fix(custom views): fix case where no custom views are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
stropitek committed Sep 21, 2016
1 parent 47830f7 commit 97e82bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ if (homeDir) {
if (databaseConfig.customDesign && databaseConfig.customDesign.views) {
var views = databaseConfig.customDesign.views;
for (var key in views) {
if (views[key].designDoc) {
designDocNames[key] = views[key].designDoc;
if(views.hasOwnProperty(key)) {
if (views[key].designDoc) {
designDocNames[key] = views[key].designDoc;
}
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,17 +905,18 @@ async function checkSecurity(db, admin) {
}

async function checkDesignDoc(db, custom) {
custom.views = custom.views || {};
var toUpdate = new Set();
debug.trace('check _design/app design doc');
const doc = await nanoPromise.getDocument(db, constants.DESIGN_DOC_ID);
if (doc === null) {
toUpdate.add(constants.DESIGN_DOC_NAME);
debug.trace('design doc missing');
debug.trace(`${constants.DESIGN_DOC_ID} missing`);
} else if (
(!doc.version || doc.version < constants.DESIGN_DOC_VERSION) ||
(custom && typeof custom.version === 'number' && (!doc.customVersion || doc.customVersion < custom.version))
) {
debug.trace('design doc needs update');
debug.trace(`${constants.DESIGN_DOC_ID} needs update`);
toUpdate.add(constants.DESIGN_DOC_NAME);
}

Expand Down Expand Up @@ -986,8 +987,6 @@ async function checkDesignDoc(db, custom) {
designDoc.views[viewName] = custom.views[viewName];
} else if (!custom.views[viewName].designDoc && designName === constants.DESIGN_DOC_NAME) {
designDoc.views[viewName] = custom.views[viewName];
designDoc.version = custom.version;
designDoc.updat;
}
}
designDoc._id = '_design/' + designName;
Expand All @@ -1000,7 +999,7 @@ async function checkDesignDoc(db, custom) {

async function createDesignDoc(db, revID, custom) {
debug.trace('create design doc');
var designDoc = getDesignDoc(custom);
var designDoc = getDesignDoc(custom, db.config.db);
if (revID) {
designDoc._rev = revID;
}
Expand Down

0 comments on commit 97e82bf

Please sign in to comment.