const fs = require("fs"); const path = require("path"); module.exports = { up: async function (query, DataTypes) { const promises = []; const vals = [], errs = []; let dataFiles = await fs.readdirSync(path.join(__dirname, "./data")); for (const jsonFile of dataFiles) { let JSONData, data, tableName; try { JSONData = JSON.parse( fs.readFileSync(path.join(__dirname, "./data", jsonFile)) ); tableName = Object.keys(JSONData)[0]; data = JSONData[tableName]; } catch (error) {} if (tableName && data && data.length > 0) { let [res, err] = await query.bulkInsert(tableName, data); res && vals.push(res); err && errs.push(err); } else { errs.push( "TableName specified does not have any data. TableName: " + tableName + "data: " + data ); } } return new Promise(async (resolve, reject) => { resolve({ vals, errs }); }); }, down: function (query, DataTypes) {}, };