Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple sequelize migration retry script
#!/usr/bin/env node
'use strict';
const program = require('commander');
const exec = require('child_process').exec;
program
.version('0.0.1')
.arguments('<direction>')
.action(function (direction) {
if (direction === 'up') {
execAndLog('sequelize db:migrate', 0, 5);
}
if (direction === 'down') {
execAndLog('sequelize db:migrate:undo', 0, 5);
}
});
program.parse(process.argv);
function execAndLog(cmd, index, retries) {
let buffer_size = 1024 * 1024 * 1; //1MB
exec(cmd, {maxBuffer: buffer_size}, function (error, stdout, stderr) {
if (error) {
if (retries === 0) {
throw error;
}
setTimeout(() => execAndLog(cmd, index, retries - 1), 3000);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment