100 lines
4.6 KiB
JavaScript
100 lines
4.6 KiB
JavaScript
const bcrypt = require("bcryptjs");
|
|
const process = require('process');
|
|
|
|
/** @type {import('sequelize-cli').Migration} */
|
|
module.exports = {
|
|
async up (queryInterface, /*Sequelize*/) {
|
|
if (process.env.NODE_ENV !== 'development') return;
|
|
|
|
await queryInterface.bulkInsert('Authentications', [
|
|
{ email: 'ryan.nolan@bullpen.com', password: bcrypt.hashSync('ryan$123', 8), createdAt: new Date(), updatedAt: new Date() },
|
|
{ email: 'sandy.koufax@bullpen.com', password: bcrypt.hashSync('sandy$123', 8), createdAt: new Date(), updatedAt: new Date() },
|
|
{ email: 'pedro.martinez@bullpen.com', password: bcrypt.hashSync('pedro$123', 8), createdAt: new Date(), updatedAt: new Date() },
|
|
{ email: 'randy.johnson@bullpen.com', password: bcrypt.hashSync('randy$123', 8), createdAt: new Date(), updatedAt: new Date() },
|
|
{ email: 'sparky.anderson@bullpen.com', password: bcrypt.hashSync('sparky$123', 8), createdAt: new Date(), updatedAt: new Date() },
|
|
]);
|
|
|
|
const auths = await queryInterface.select(null, 'Authentications');
|
|
const ryanAuthId = auths.filter((auth) => auth.email === 'ryan.nolan@bullpen.com').map((auth) => auth.id).shift();
|
|
const sandyAuthId = auths.filter((auth) => auth.email === 'sandy.koufax@bullpen.com').map((auth) => auth.id).shift();
|
|
const pedroAuthId = auths.filter((auth) => auth.email === 'pedro.martinez@bullpen.com').map((auth) => auth.id).shift();
|
|
const randyAuthId = auths.filter((auth) => auth.email === 'randy.johnson@bullpen.com').map((auth) => auth.id).shift();
|
|
const sparkyAuthId = auths.filter((auth) => auth.email === 'sparky.anderson@bullpen.com').map((auth) => auth.id).shift();
|
|
|
|
await queryInterface.bulkInsert('Users', [{
|
|
firstName: 'Nolan',
|
|
lastName: 'Ryan',
|
|
dateOfBirth: new Date(1947, 1, 31),
|
|
gender: 'male',
|
|
handedness: 'right',
|
|
authId: ryanAuthId,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
}, {
|
|
firstName: 'Sandy',
|
|
lastName: 'Koufax',
|
|
dateOfBirth: new Date(1935, 12, 30),
|
|
gender: 'male',
|
|
handedness: 'right',
|
|
authId: sandyAuthId,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
}, {
|
|
firstName: 'Pedro',
|
|
lastName: 'Martinez',
|
|
dateOfBirth: new Date(1971, 10, 25),
|
|
gender: 'male',
|
|
handedness: 'right',
|
|
authId: pedroAuthId,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
}, {
|
|
firstName: 'randy',
|
|
lastName: 'johnson',
|
|
dateOfBirth: new Date(1963, 9, 10),
|
|
gender: 'male',
|
|
handedness: 'right',
|
|
authId: randyAuthId,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
}, {
|
|
firstName: 'Sparky',
|
|
lastName: 'Anderson',
|
|
dateOfBirth: new Date(1934, 22, 2),
|
|
gender: 'male',
|
|
authId: sparkyAuthId,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
}]);
|
|
|
|
const users = await queryInterface.select(null, 'Users');
|
|
const ryanId = users.filter((user) => user.firstName === 'Ryan').map((user) => user.id).shift();
|
|
const sandyId = users.filter((user) => user.firstName === 'Sandy').map((user) => user.id).shift();
|
|
const pedroId = users.filter((user) => user.firstName === 'Pedro').map((user) => user.id).shift();
|
|
const randyId = users.filter((user) => user.firstName === 'Randy').map((user) => user.id).shift();
|
|
const sparkyId = users.filter((user) => user.firstName === 'Sparky').map((user) => user.id).shift();
|
|
|
|
const roles = await queryInterface.select(null, 'Roles');
|
|
const playerId = roles.filter((role) => role.name === 'player').map((role) => role.id).shift();
|
|
const coachId = roles.filter((role) => role.name === 'coach').map((role) => role.id).shift();
|
|
const adminId = roles.filter((role) => role.name === 'admin').map((role) => role.id).shift();
|
|
|
|
await queryInterface.bulkInsert('UserRoles', [
|
|
{ userId: ryanId, roleId: playerId, createdAt: new Date(), updatedAt: new Date() },
|
|
{ userId: sandyId, roleId: playerId, createdAt: new Date(), updatedAt: new Date() },
|
|
{ userId: pedroId, roleId: playerId, createdAt: new Date(), updatedAt: new Date() },
|
|
{ userId: randyId, roleId: playerId, createdAt: new Date(), updatedAt: new Date() },
|
|
{ userId: sparkyId, roleId: coachId, createdAt: new Date(), updatedAt: new Date() },
|
|
{ userId: sparkyId, roleId: adminId, createdAt: new Date(), updatedAt: new Date() },
|
|
]);
|
|
},
|
|
|
|
async down (queryInterface, /*Sequelize*/) {
|
|
if (process.env.NODE_ENV !== 'development') return;
|
|
|
|
await queryInterface.dropTable('Authentications');
|
|
await queryInterface.dropTable('Users');
|
|
await queryInterface.dropTable('UserRoles');
|
|
}
|
|
};
|