east-mongo
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -21,3 +21,3 @@ 'use strict'; | ||
self.collection = db.collection('_migrations'); | ||
callback(null, {db: db}); | ||
callback(null, {db: db, dropIndexIfExists: dropIndexIfExists}); | ||
}); | ||
@@ -45,2 +45,28 @@ }; | ||
/** | ||
* Helpers which will be exposed to migration | ||
*/ | ||
function dropIndexIfExists(collection, index, callback) { | ||
var indexName = ''; | ||
// convert object to string coz `indexExists` don't recognize objects | ||
if (typeof index === 'object') { | ||
for (var key in index) { | ||
indexName += '_' + key + '_' + index[key]; | ||
} | ||
indexName = indexName.replace(/^_/, ''); | ||
} else { | ||
indexName = index; | ||
} | ||
collection.indexExists(indexName, function(err, exist) { | ||
if (err) {callback(err); return;} | ||
if (exist) { | ||
collection.dropIndex(indexName, callback); | ||
} else { | ||
callback(); | ||
} | ||
}); | ||
} | ||
module.exports = Adapter; |
{ | ||
"name": "east-mongo", | ||
"description": "mongodb adapter for \"east\" (node.js database migration tool)", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Oleg Korobenko <oleg.korobenko@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
66
2374
3
1
0