From 289da1528a9dcab492289bd080c71d9a48189d30 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 01:23:30 -0400 Subject: [PATCH 1/5] don't let down migration hang if nothing to rollback --- core_functions.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core_functions.js b/core_functions.js index b724cdf..5f30d9a 100644 --- a/core_functions.js +++ b/core_functions.js @@ -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(); } }); } From ee4d25a66d00945b57b550f9aa971814e1122413 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 01:24:47 -0400 Subject: [PATCH 2/5] verify migration down no longer hangs with zero migrations --- test/core_functions.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/core_functions.js b/test/core_functions.js index 7502daf..165b194 100644 --- a/test/core_functions.js +++ b/test/core_functions.js @@ -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); + }); + }); + }) + }) }); From 70febf8ee3abb471a10a6c136c425c875adffb0e Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 01:25:20 -0400 Subject: [PATCH 3/5] ensure migration table exists for testing --- test/test_commons.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test_commons.js b/test/test_commons.js index 6be62c4..2a935e3 100644 --- a/test/test_commons.js +++ b/test/test_commons.js @@ -30,8 +30,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(); + }); }); }); }); From 80e868a08a5469a3d550b14715f39c28e3d8b519 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 01:28:32 -0400 Subject: [PATCH 4/5] only test javascript files --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfaab24..0a641be 100644 --- a/package.json +++ b/package.json @@ -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", From ca2ee2bebf0fd35acbb057ad4302ba7b00fb6fb9 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 01:29:13 -0400 Subject: [PATCH 5/5] include config file for migration table --- test/test_commons.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_commons.js b/test/test_commons.js index 2a935e3..f0fd170 100644 --- a/test/test_commons.js +++ b/test/test_commons.js @@ -1,5 +1,6 @@ var mysql = require('./mysql'); var fs = require('fs'); +var config = require('../config.js'); function deleteFolderRecursive(path) { if (fs.existsSync(path)) {