mecano
Version:
Common functions for system deployment.
58 lines (55 loc) • 1.64 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var db;
module.exports = {
shy: true,
handler: function(options) {
var cmd, k, ref, ref1, v;
if (options.db == null) {
options.db = {};
}
ref = options.db;
for (k in ref) {
v = ref[k];
if (options[k] == null) {
options[k] = v;
}
}
if (options.database == null) {
options.database = options.argument;
}
if (!options.host) {
throw Error('Missing option: "host"');
}
if (!options.admin_username && !options.username) {
throw Error('Missing option: "username" or "admin_username"');
}
if (options.admin_username && !options.admin_password) {
throw Error('Missing option: "admin_password"');
}
if (options.username && !options.password) {
throw Error('Missing option: "password"');
}
options.engine = options.engine.toLowerCase();
if ((ref1 = options.engine) !== 'mysql' && ref1 !== 'postgres') {
throw Error("Unsupport engine: " + (JSON.stringify(options.engine)));
}
if (options.port == null) {
options.port = 5432;
}
cmd = (function() {
switch (options.engine) {
case 'mysql':
return db.cmd(options, {
database: 'mysql'
}, "SHOW DATABASES") + (" | grep -w '" + options.database + "'");
case 'postgres':
return db.cmd(options, "SELECT datname FROM pg_database WHERE datname = '" + options.database + "'") + (" | grep -w '" + options.database + "'");
}
})();
return this.execute({
cmd: cmd,
code_skipped: 1
});
}
};
db = require('../../misc/db');