Files
censo2020Back/server/models/install.js
T
alfredojl 2b232f2c03 Login
2020-08-17 11:35:15 -05:00

62 lines
1.3 KiB
JavaScript

const logSymbols = require("log-symbols");
const colors = require("colors");
const bcrypt = require("bcrypt");
const admin = require("./tablas/Admin");
require("../config/config");
async function remove() {
console.log(logSymbols.info, "Paso 1 : Borrando base de datos \n".blue.bold);
await admin.drop();
console.log(logSymbols.success, "admin");
}
async function install() {
console.log(
logSymbols.info,
"Paso 2 : Instalando base de datos \n".blue.bold
);
await admin.sync();
console.log(logSymbols.success, "admin");
//crear clave foranea de una tabla a otra, ejemplo
// responsable.hasMany(programa, {
// foreignKey: "idResponsable",
// });
};
async function createFirstUsers() {
console.log(
logSymbols.info,
"Paso 3 : Creating first users in database...\n".blue.bold
);
await admin.create({
name: 'alima',
password: bcrypt.hashSync('contraseña', 10),
isAdmin: true
});
await admin.create({
name: 'alfredojl',
password: bcrypt.hashSync('contraseña', 10),
isAdmin: false
});
}
async function exec() {
await remove();
await install();
await createFirstUsers();
console.log(logSymbols.success, "Éxito al instalar \n".underline.bold.green);
process.exit();
}
exec();