This commit is contained in:
alfredojl
2020-08-17 11:35:15 -05:00
parent 1ae438a299
commit 2b232f2c03
10 changed files with 183 additions and 85 deletions
+40 -19
View File
@@ -7,35 +7,56 @@ const admin = require("./tablas/Admin");
require("../config/config");
async function remove() {
console.log(logSymbols.info, "Paso 1 : Borrando base de datos \n".blue.bold);
console.log(logSymbols.info, "Paso 1 : Borrando base de datos \n".blue.bold);
await admin.drop();
console.log(logSymbols.success, "admin");
await admin.drop();
console.log(logSymbols.success, "admin");
}
async function install() {
console.log(
logSymbols.info,
"Paso 2 : Instalando base de datos \n".blue.bold
);
console.log(
logSymbols.info,
"Paso 2 : Instalando base de datos \n".blue.bold
);
await admin.sync();
console.log(logSymbols.success, "admin");
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
});
//crear clave foranea de una tabla a otra, ejemplo
// responsable.hasMany(programa, {
// foreignKey: "idResponsable",
// });
}
async function exec() {
await remove();
await install();
await remove();
await install();
await createFirstUsers();
console.log(logSymbols.success, "Éxito al instalar \n".underline.bold.green);
process.exit();
console.log(logSymbols.success, "Éxito al instalar \n".underline.bold.green);
process.exit();
}
exec();
exec();
+18 -17
View File
@@ -2,27 +2,28 @@ const Sequelize = require("sequelize");
const sequelize = require("../../config/sequelize.conf");
class Admin extends Sequelize.Model {}
Admin.init(
{
Admin.init({
idAdmin: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
nombre: {
type: Sequelize.STRING(50),
allowNull: false,
name: {
type: Sequelize.STRING(50),
allowNull: false,
},
password: {
type: Sequelize.STRING(100),
allowNull: false,
type: Sequelize.STRING(100),
allowNull: false,
},
},
{
isAdmin: {
type: Sequelize.BOOLEAN,
allowNull: false
}
}, {
sequelize,
tableName: "admin",
}
);
tableName: "users",
});
module.exports = Admin;
module.exports = Admin;