rmcouchdb doesn't drop everything if dbname is absent; mkcouchdb reports helpful error message if dbname is absent
This commit is contained in:
parent
af73a33070
commit
a41ae8efac
|
@ -68,8 +68,7 @@ possible to write in your configuration file:
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Note, however, that if you call 'rmcouchdb' without a sub-argument, in
|
Note that if you call `rmcouchdb` without a sub-argument, it will not delete any databases.
|
||||||
keeping with grunt's standards, it will drop *all* of your databases!
|
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
|
|
|
@ -46,21 +46,26 @@ module.exports = function(grunt) {
|
||||||
dbname = parts.pathname.replace(/^\//, '');
|
dbname = parts.pathname.replace(/^\//, '');
|
||||||
try {
|
try {
|
||||||
nano = require('nano')(parts.protocol + '//' + parts.host);
|
nano = require('nano')(parts.protocol + '//' + parts.host);
|
||||||
nano.db.destroy(dbname, function(err) {
|
if (dbname) {
|
||||||
if (err) {
|
nano.db.destroy(dbname, function(err) {
|
||||||
if (err.status_code && err.status_code === 404) {
|
if (err) {
|
||||||
if (_this.data.options && _this.data.options.okay_if_missing) {
|
if (err.status_code && err.status_code === 404) {
|
||||||
grunt.log.writeln("Database " + dbname + " not present... skipping.");
|
if (_this.data.options && _this.data.options.okay_if_missing) {
|
||||||
return done(null, null) ;
|
grunt.log.writeln("Database " + dbname + " not present... skipping.");
|
||||||
|
return done(null, null) ;
|
||||||
|
} else {
|
||||||
|
grunt.warn("Database " + dbname + " does not exist.");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
grunt.warn("Database " + dbname + " does not exist.");
|
grunt.warn(err);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
grunt.warn(err);
|
|
||||||
}
|
}
|
||||||
}
|
return done(err, null);
|
||||||
return done(err, null);
|
});
|
||||||
});
|
} else {
|
||||||
|
grunt.log.writeln("No database specified... skipping.");
|
||||||
|
return done(null, null);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
grunt.warn(e);
|
grunt.warn(e);
|
||||||
done(e, null);
|
done(e, null);
|
||||||
|
@ -74,20 +79,26 @@ module.exports = function(grunt) {
|
||||||
parts = urls.parse(this.data.db);
|
parts = urls.parse(this.data.db);
|
||||||
dbname = parts.pathname.replace(/^\//, '');
|
dbname = parts.pathname.replace(/^\//, '');
|
||||||
try {
|
try {
|
||||||
nano = require('nano')(parts.protocol + '//' + parts.host);
|
if (dbname) {
|
||||||
nano.db.create(dbname, function(err) {
|
nano = require('nano')(parts.protocol + '//' + parts.host);
|
||||||
if (_this.data.options && _this.data.options.okay_if_exists) {
|
nano.db.create(dbname, function(err) {
|
||||||
if (err){
|
if (_this.data.options && _this.data.options.okay_if_exists) {
|
||||||
grunt.log.writeln("Database " + dbname + " exists, skipping");
|
if (err){
|
||||||
|
grunt.log.writeln("Database " + dbname + " exists, skipping");
|
||||||
|
}
|
||||||
|
return done(null, null);
|
||||||
|
} else {
|
||||||
|
if (err){
|
||||||
|
grunt.warn(err);
|
||||||
|
}
|
||||||
|
return done(err, null);
|
||||||
}
|
}
|
||||||
return done(null, null);
|
});
|
||||||
} else {
|
} else {
|
||||||
if (err){
|
var err_msg = "No database specified... skipping.";
|
||||||
grunt.warn(err);
|
grunt.warn(err_msg);
|
||||||
}
|
return done(new Error(err_msg), null);
|
||||||
return done(err, null);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
grunt.warn(e);
|
grunt.warn(e);
|
||||||
done(e, null);
|
done(e, null);
|
||||||
|
|
Loading…
Reference in New Issue