From 3df51cc1218493d810f5bc9b648da7846b044213 Mon Sep 17 00:00:00 2001 From: alfredojl Date: Wed, 7 Oct 2020 18:57:34 -0500 Subject: [PATCH] . --- .gitignore | 1 - helpers/tables/Ubicacion.js | 54 +++++++++++++++++++++++-------------- server/models/Ubicacion.js | 22 +++++++++++++++ 3 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 server/models/Ubicacion.js diff --git a/.gitignore b/.gitignore index 4167d68..1bb4a98 100644 --- a/.gitignore +++ b/.gitignore @@ -39,7 +39,6 @@ jspm_packages/ ./.env scratch/ ./server/controller/api -/temp # TypeScript v1 declaration files typings/ diff --git a/helpers/tables/Ubicacion.js b/helpers/tables/Ubicacion.js index 6830c30..d886d09 100644 --- a/helpers/tables/Ubicacion.js +++ b/helpers/tables/Ubicacion.js @@ -1,22 +1,36 @@ -const Sequelize = require("sequelize"); -const sequelize = require("../../config/sequelize.conf"); +const Ubicacion = require('../../server/models/tablas/Ubicacion'); +const progress = require('cli-progress'); +const colors = require('colors'); -class Ubicacion extends Sequelize.Model {} -Ubicacion.init({ - idUbicacion: { - type: Sequelize.INTEGER, - primaryKey: true, - autoIncrement: true, - allowNull: false, - }, - ubicacion: { - type: Sequelize.CHAR, - allowNull: false, - // unique: true - }, -}, { - sequelize, - tableName: "ubicacion", -}); +const faker = require('faker'); +faker.locale = "es_MX"; -module.exports = Ubicacion; \ No newline at end of file +async function fillUbicacion() { + let ubicaciones = require('./ubicaciones'); + let limit = ubicacion.length; + const bar = new progress.SingleBar({ + format: 'ubicacion |' + colors.cyan('{bar}') + '| {percentage}%' + ' || {value}/{total} records created.', + barCompleteChar: '\u2588', + barIncompleteChar: '\u2591', + hideCursor: true, + stopOnComplete: true, + barsize: 30, + align: 'right' + }); + + console.log('\n\tFilling out «ubicacion».'.cyan.italic.bold); + + bar.start(limit, 0); + for (ubicacion of ubicaciones) { + await Ubicacion.create({ + ubicacion + }) + .catch(() => { + bar.stop(); + throw new Error(); + }); + bar.increment(); + }; +}; + +module.exports = fillUbicacion; \ No newline at end of file diff --git a/server/models/Ubicacion.js b/server/models/Ubicacion.js new file mode 100644 index 0000000..6830c30 --- /dev/null +++ b/server/models/Ubicacion.js @@ -0,0 +1,22 @@ +const Sequelize = require("sequelize"); +const sequelize = require("../../config/sequelize.conf"); + +class Ubicacion extends Sequelize.Model {} +Ubicacion.init({ + idUbicacion: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true, + allowNull: false, + }, + ubicacion: { + type: Sequelize.CHAR, + allowNull: false, + // unique: true + }, +}, { + sequelize, + tableName: "ubicacion", +}); + +module.exports = Ubicacion; \ No newline at end of file