From 3ef1822cac9ef47d37b58602ef3c1719080315de Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 03:28:11 -0400 Subject: [PATCH 1/3] write file name being processed --- query.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/query.js b/query.js index 9ea29d1..95c4933 100644 --- a/query.js +++ b/query.js @@ -36,7 +36,10 @@ function execute_query(conn, path, final_file_paths, type, cb, run) { var current_file_path = path + "/" + file_name; var queries = require(current_file_path); - console.info(colors.green("Run: " + run + " Type: " + type.toUpperCase() + ": " +queries[type])); + console.info(colors.green( + `Run: ${run} Type: ${type.toUpperCase()}: ${file_name}` + )); + console.info(colors.gray(queries[type])); var timestamp_val = file_name.split("_", 1)[0]; if (typeof(queries[type]) == 'string') { From 1c4aee14c264a060fed2ccc1393860a88e72c2e1 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 03:28:50 -0400 Subject: [PATCH 2/3] clear migration table --- test/test_commons.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_commons.js b/test/test_commons.js index 6be62c4..9e3e412 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'); function deleteFolderRecursive(path) { if (fs.existsSync(path)) { @@ -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(`delete from ${config.table}`, function (error) { + if (error) throw error; + deleteFolderRecursive(__dirname + '/migrations'); + cb(); + }) }); }); }); From 770f75ed6b06a598ea71487e7696180c7ed0a266 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Mon, 3 Jun 2024 03:29:45 -0400 Subject: [PATCH 3/3] test file name is written to console --- test/query.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/query.js b/test/query.js index fff2c58..b21b5fc 100644 --- a/test/query.js +++ b/test/query.js @@ -4,6 +4,7 @@ var queryFunctions = require('../query'); var testCommons = require('./test_commons'); var mysql = require('./mysql'); var assert = require('assert'); +var fs = require('fs'); var should = chai.should(); @@ -11,6 +12,41 @@ describe('query.js', function() { before(function (done) { testCommons(done); }); + after(function (done) { + testCommons(done); + }); + + context('execute_query', function () { + it('should write file name', function (done) { + const name = '1_should_write_file_name.js'; + fs.writeFileSync( + __dirname + '/migrations/' + name, + `module.exports={up: "select 1", down: "select 2"};`, + { encoding: 'utf-8' } + ); + + mysql.getConnection(function (err, connection) { + if (err) throw err; + + var files = [{ + timestamp: 1, file_path: name + }]; + var oldInfo = console.info; + var loggedFile = false; + console.info = (arg1) => { + if (`${arg1}`.includes(name)) { + loggedFile = true; + } + }; + + queryFunctions.execute_query(mysql, __dirname + '/migrations', files, 'up', function () { + console.info = oldInfo.bind(console); + assert.ok(loggedFile, 'File name was logged.'); + done(); + }); + }); + }) + }); context('updateRecords', function () { var timestamp = Date.now();