From 81a05a64d135e3e4fd6efa9d45f5e7c176b2d560 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Sun, 26 Feb 2017 10:49:51 -0800 Subject: [PATCH] Moving sql_sync to async each Updated SQL_MIGRATIONS to pool. --- SQL_MIGRATIONS.md | 2 +- sql_sync/sql_sync.js | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/SQL_MIGRATIONS.md b/SQL_MIGRATIONS.md index 5c8a729..355b13d 100644 --- a/SQL_MIGRATIONS.md +++ b/SQL_MIGRATIONS.md @@ -31,5 +31,5 @@ ALTER TABLE pool.xmrtoTxn CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; 2/25/2017 --------- ```sql -ALTER TABLE monero_live.users ADD enable_email BOOL DEFAULT true NULL; +ALTER TABLE pool.users ADD enable_email BOOL DEFAULT true NULL; ``` \ No newline at end of file diff --git a/sql_sync/sql_sync.js b/sql_sync/sql_sync.js index e7e39a4..6306b48 100644 --- a/sql_sync/sql_sync.js +++ b/sql_sync/sql_sync.js @@ -3,6 +3,7 @@ let mysql = require("promise-mysql"); let fs = require("fs"); let config = fs.readFileSync("../config.json"); let sql_schema = fs.readFileSync("config_entries.json"); +let async = require("async"); global.config = JSON.parse(config); global.mysql = mysql.createPool(global.config.mysql); @@ -13,21 +14,18 @@ global.schema = JSON.parse(sql_schema); let loopCount = 0; let updatedCount = 0; -global.schema.forEach(function(entry){ +async.eachSeries(global.schema, function(entry, callback){ global.mysql.query("SELECT * FROM config WHERE module = ? AND item = ?", [entry.module, entry.item]).then(function(rows){ loopCount += 1; if (rows.length > 0){ - if(loopCount === global.schema.length){ - console.log("Updated SQL schema with "+updatedCount+" new rows! Exiting!"); - process.exit(); - } - return; + callback(); } updatedCount += 1; - global.mysql.query("INSERT INTO config (module, item, item_value, item_type, Item_desc) VALUES (?, ?, ?, ?, ?)", [entry.module, entry.item, entry.item_value, entry.item_type, entry.Item_desc]); - if(loopCount === global.schema.length){ - console.log("Updated SQL schema with "+updatedCount+" new rows! Exiting!"); - process.exit(); - } + global.mysql.query("INSERT INTO config (module, item, item_value, item_type, Item_desc) VALUES (?, ?, ?, ?, ?)", [entry.module, entry.item, entry.item_value, entry.item_type, entry.Item_desc]).then(function(){ + callback(); + }); }); +}, function(){ + console.log("Updated SQL schema with "+updatedCount+" new rows! Exiting!"); + process.exit(); }); \ No newline at end of file