index.js
function migrations(direction, lastMigrationNum, migrateTo) {
		var isDirectionUp = direction === 'up',
			hasMigrateTo = !!migrateTo,
			migrateToNum = hasMigrateTo ? parseInt(migrateTo, 10) : undefined,
			migrateToFound = !hasMigrateTo;

		var migrationsToRun = fs.readdirSync('migrations')
			.filter(function (file) {
				var formatCorrect = file.match(/^\d+.*\.js$/),
					migrationNum = formatCorrect && parseInt(file.match(/^\d+/)[0], 10),
					isRunnable = formatCorrect && isDirectionUp ? migrationNum > lastMigrationNum : migrationNum <= lastMigrationNum,
					isFile = fs.statSync(path.join('migrations', file)).isFile();

				if (isFile && !formatCorrect) {
					console.log('"' + file + '" ignored. Does not match migration naming schema');
				}

				return formatCorrect && isRunnable && isFile;
			}).sort(function (a, b) {
				var aMigrationNum = parseInt(a.match(/^\d+/)[0], 10),
						bMigrationNum = parseInt(b.match(/^\d+/)[0], 10);

				if (aMigrationNum > bMigrationNum) {
					return isDirectionUp ? 1 : -1;
				}
				if (aMigrationNum < bMigrationNum) {
					return isDirectionUp ? -1 : 1;
				}

				return 0;
			}).filter(function(file){
				var formatCorrect = file.match(/^\d+.*\.js$/),
					migrationNum = formatCorrect && parseInt(file.match(/^\d+/)[0], 10),
					isRunnable = formatCorrect && isDirectionUp ? migrationNum > lastMigrationNum : migrationNum <= lastMigrationNum;

				if (hasMigrateTo) {
					if (migrateToNum === migrationNum) {
						migrateToFound = true;
					}

					if (isDirectionUp) {
						isRunnable = isRunnable && migrateToNum >= migrationNum;
					} else {
						isRunnable = isRunnable && migrateToNum < migrationNum;
					}
				}

				return formatCorrect && isRunnable;
			}).map(function(file){
				return 'migrations/' + file;
			});

		if (!migrateToFound) {
			return abort('migration `'+ migrateTo + '` not found!');
		}

		return migrationsToRun;
	}
function migrations(direction, lastMigrationNum, migrateTo) {
		var isDirectionUp = direction === 'up',
			hasMigrateTo = !!migrateTo,
			migrateToNum = hasMigrateTo ? parseInt(migrateTo, 10) : undefined,
			migrateToFound = !hasMigrateTo;

		var migrationsToRun = fs.readdirSync('migrations')
			.filter(function (file) {
				var formatCorrect = file.match(/^\d+.*\.js$/),
					migrationNum = formatCorrect && parseInt(file.match(/^\d+/)[0], 10),
					isRunnable = formatCorrect && isDirectionUp ? migrationNum > lastMigrationNum : migrationNum <= lastMigrationNum,
					isFile = fs.statSync(path.join('migrations', file)).isFile();

				if (isFile && !formatCorrect) {
					console.log('"' + file + '" ignored. Does not match migration naming schema');
				}

				return formatCorrect && isRunnable && isFile;
			}).sort(function (a, b) {
				var aMigrationNum = parseInt(a.match(/^\d+/)[0], 10),
						bMigrationNum = parseInt(b.match(/^\d+/)[0], 10);

				if (aMigrationNum > bMigrationNum) {
					return isDirectionUp ? 1 : -1;
				}
				if (aMigrationNum < bMigrationNum) {
					return isDirectionUp ? -1 : 1;
				}

				return 0;
			}).filter(function(file){
				var formatCorrect = file.match(/^\d+.*\.js$/),
					migrationNum = formatCorrect && parseInt(file.match(/^\d+/)[0], 10),
					isRunnable = formatCorrect && isDirectionUp ? migrationNum > lastMigrationNum : migrationNum <= lastMigrationNum;

				if (hasMigrateTo) {
					if (migrateToNum === migrationNum) {
						migrateToFound = true;
					}

					if (isDirectionUp) {
						isRunnable = isRunnable && migrateToNum >= migrationNum;
					} else {
						isRunnable = isRunnable && migrateToNum < migrationNum;
					}
				}

				return formatCorrect && isRunnable;
			}).map(function(file){
				return 'migrations/' + file;
			});

		if (!migrateToFound) {
			return abort('migration `'+ migrateTo + '` not found!');
		}

		return migrationsToRun;
	}
function migrations ( direction , lastMigrationNum , migrateTo ) { var isDirectionUp = direction === 'up' , hasMigrateTo = ! ! migrateTo , migrateToNum = hasMigrateTo ? parseInt ( migrateTo , 10 ) : undefined , migrateToFound = ! hasMigrateTo ; var migrationsToRun = fs . readdirSync ( 'migrations' ) . filter ( function ( file ) { var formatCorrect = file . match ( / ^\d+.*\.js$ / ) , migrationNum = formatCorrect && parseInt ( file . match ( / ^\d+ / ) [ 0 ] , 10 ) , isRunnable = formatCorrect && isDirectionUp ? migrationNum > lastMigrationNum : migrationNum <= lastMigrationNum , isFile = fs . statSync ( path . join ( 'migrations' , file ) ) . isFile ( ) ; if ( isFile && ! formatCorrect ) { console . log ( '"' + file + '" ignored. Does not match migration naming schema' ) ; } return formatCorrect && isRunnable && isFile ; } ) . sort ( function ( a , b ) { var aMigrationNum = parseInt ( a . match ( / ^\d+ / ) [ 0 ] , 10 ) , bMigrationNum = parseInt ( b . match ( / ^\d+ / ) [ 0 ] , 10 ) ; if ( aMigrationNum > bMigrationNum ) { return isDirectionUp ? 1 : - 1 ; } if ( aMigrationNum < bMigrationNum ) { return isDirectionUp ? - 1 : 1 ; } return 0 ; } ) . filter ( function ( file ) { var formatCorrect = file . match ( / ^\d+.*\.js$ / ) , migrationNum = formatCorrect && parseInt ( file . match ( / ^\d+ / ) [ 0 ] , 10 ) , isRunnable = formatCorrect && isDirectionUp ? migrationNum > lastMigrationNum : migrationNum <= lastMigrationNum ; if ( hasMigrateTo ) { if ( migrateToNum === migrationNum ) { migrateToFound = true ; } if ( isDirectionUp ) { isRunnable = isRunnable && migrateToNum >= migrationNum ; } else { isRunnable = isRunnable && migrateToNum < migrationNum ; } } return formatCorrect && isRunnable ; } ) . map ( function ( file ) { return 'migrations/' + file ; } ) ; if ( ! migrateToFound ) { return abort ( 'migration `' + migrateTo + '` not found!' ) ; } return migrationsToRun ; }
Load migrations.
@param {String} direction
@param {Number} lastMigrationNum
@param {Number} migrateTo
Load migrations .