Created
March 15, 2012 16:07
-
-
Save anatoliychakkaev/2044984 to your computer and use it in GitHub Desktop.
RailwayJS database tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.init = function () { | |
railway.tools.database = function db() { | |
var action = process.argv[3]; | |
switch (action) { | |
case 'migrate': | |
case 'update': | |
perform(action, process.exit); | |
break; | |
default: | |
console.log('Unknown action', action); | |
break; | |
} | |
}; | |
railway.tools.database.help = { | |
shortcut: 'db', | |
usage: 'db [migrate|update]', | |
description: 'Run database migrations' | |
}; | |
}; | |
function getUniqueSchemas() { | |
var schemas = []; | |
Object.keys(app.models).forEach(function (modelName) { | |
var Model = app.models[modelName]; | |
var schema = Model.schema; | |
if (!~schemas.indexOf(schema)) { | |
schemas.push(schema); | |
} | |
}); | |
return schemas; | |
} | |
function perform(action, callback) { | |
console.log('Perform', action, 'on'); | |
var wait = 0; | |
getUniqueSchemas().forEach(function (schema) { | |
if (schema['auto' + action]) { | |
console.log(' - ' + schema.name); | |
wait += 1; | |
process.nextTick(function () { | |
schema['auto' + action](done); | |
}); | |
} | |
}); | |
if (wait === 0) done(); else console.log(wait); | |
function done() { | |
if (--wait === 0) callback(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('db-tools'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, I got this error. This is related to connection timeout. It will be fixed in next release.