Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ function down_migrations(conn, max_count, path, cb) {
var final_file_paths = file_paths.sort(function(a, b) { return (b.timestamp - a.timestamp)}).slice(0, max_count);
queryFunctions.execute_query(conn, path, final_file_paths, 'down', cb);
});
} else {
console.info(colors.blue("No more DOWN migrations to run"));
cb();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A tool to use with mysql package to maintain migrations",
"main": "index.js",
"scripts": {
"test": "node node_modules/.bin/mocha test/*"
"test": "node node_modules/.bin/mocha test/*.js"
},
"repository": {
"type": "git",
Expand Down
13 changes: 13 additions & 0 deletions test/core_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ describe('core_functions.js', function() {
});
});
});

describe('down', function () {
context('zero migrations', function () {
it('', function (done) {
const zeroMigrations = 0;
var path = __dirname + '/migrations';
mysql.getConnection(function (err, connection) {
if (err) throw err;
coreFunctions.down_migrations(mysql, zeroMigrations, path, done);
});
});
})
})
});
8 changes: 6 additions & 2 deletions test/test_commons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var mysql = require('./mysql');
var fs = require('fs');
var config = require('../config.js');

function deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
Expand Down Expand Up @@ -30,8 +31,11 @@ module.exports = function(cb) {
if (error) throw error;
connection.query("DROP TABLE IF EXISTS user5", function (error) {
if (error) throw error;
deleteFolderRecursive(__dirname + '/migrations');
cb();
connection.query("CREATE TABLE IF NOT EXISTS `" + config.table + "` (`timestamp` varchar(254) NOT NULL UNIQUE)", function (error, results) {
if (error) throw error;
deleteFolderRecursive(__dirname + '/migrations');
cb();
});
});
});
});
Expand Down