Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function executeCreate()
{
var folder, path;
if ( argv._.length === 0 )
{
log.error( '\'migrationName\' is required.' );
optimist.showHelp();
process.exit( 1 );
}
createMigrationDir( argv[ 'migrations-dir' ], function ( err )
{
if ( err )
{
log.error( 'Failed to create migration directory at ', argv[ 'migrations-dir' ], err );
process.exit( 1 );
}
argv.title = argv._.shift();
folder = argv.title.split( '/' );
argv.title = folder[ folder.length - 2 ] || folder[ 0 ];
case 'db':
loadConfig();
if( folder.length < 1 )
{
log.info( 'Please enter a valid command, i.e. db:create|db:drop' );
}
else
{
global.mode = folder[ 1 ];
executeDB();
}
break;
default:
log.error( 'Invalid Action: Must be [up|down|create].' );
optimist.showHelp();
process.exit( 1 );
break;
}
}
createMigrationDir( argv[ 'migrations-dir' ], function ( err )
{
if ( err )
{
log.error( 'Failed to create migration directory at ', argv[ 'migrations-dir' ], err );
process.exit( 1 );
}
var migration = config.getCurrent().settings.database;
config.getCurrent().settings.diffDump = true;
config.getCurrent().settings.database = migration + '_diff';
config.getCurrent().settings.database_diff = migration + '_diff';
executeUp( function ( err, complete, callback )
{
if ( err )
process.exit( 1 );
callback( function ( err )
{
if ( err )
process.on( 'uncaughtException', function ( err )
{
log.error( err.stack );
process.exit( 1 );
} );
createMigrationDir( sqlDir, function( err )
{
if ( err )
{
log.error( 'Failed to create migration directory at ', sqlDir, err );
process.exit( 1 );
}
var templateTypeDefaultSQL = Migration.TemplateType.DEFAULT_SQL;
var migrationUpSQL = new Migration( argv.title + '-up.sql', sqlDir, new Date(), templateTypeDefaultSQL );
index.createMigration( migrationUpSQL, function( err, migration )
{
assert.ifError( err );
log.info( util.format( 'Created migration up sql file at %s', migration.path ) );
} );
var migrationDownSQL = new Migration( argv.title + '-down.sql', sqlDir, new Date(), templateTypeDefaultSQL );
index.createMigration( migrationDownSQL, function( err, migration )
{
assert: function( condition, level, message )
{
if( typeof( level ) === 'string' )
{
message = level;
level = { critical: false };
}
if( !condition )
{
return true;
}
log.error( message );
if( level.critical )
throw ( condition );
return false;
},