const bcrypt = require("bcryptjs"); const process = require('process'); /** @type {import('sequelize-cli').Migration} */ module.exports = { async up (queryInterface, /*Sequelize*/) { if (process.env.NODE_ENV !== 'production') return; await queryInterface.bulkInsert('Authentications', [ { email: 'admin@example.com', password: bcrypt.hashSync('admin$123', 8), createdAt: new Date(), updatedAt: new Date() }, { email: 'kuehl.julian@gmail.com', password: bcrypt.hashSync('julian$123', 8), createdAt: new Date(), updatedAt: new Date() }, { email: 'cichocki.c@gmail.com', password: bcrypt.hashSync('clemens$123', 8), createdAt: new Date(), updatedAt: new Date() } ]); const auths = await queryInterface.select(null, 'Authentications'); const adminAuthId = auths.filter((auth) => auth.email === 'admin@example.com').map((auth) => auth.id).shift(); const julianAuthId = auths.filter((auth) => auth.email === 'kuehl.julian@gmail.com').map((auth) => auth.id).shift(); const clemensAuthId = auths.filter((auth) => auth.email === 'cichocki.c@gmail.com').map((auth) => auth.id).shift(); await queryInterface.bulkInsert('Users', [{ firstName: 'Admin', lastName: 'Bullpen', dateOfBirth: '1970-01-01', gender: 'other', authId: adminAuthId, createdAt: new Date(), updatedAt: new Date(), }, { firstName: 'Julian', lastName: 'Kühl', dateOfBirth: '2009-08-08', gender: 'male', authId: julianAuthId, createdAt: new Date(), updatedAt: new Date(), }, { firstName: 'Clemens', lastName: 'Cichocki', dateOfBirth: '1970-01-01', gender: 'male', authId: clemensAuthId, createdAt: new Date(), updatedAt: new Date(), }]); const users = await queryInterface.select(null, 'Users'); const adminUserId = users.filter((user) => user.firstName === 'Admin').map((user) => user.id).shift(); const julianUserId = users.filter((user) => user.firstName === 'Julian').map((user) => user.id).shift(); const clemensUserId = users.filter((user) => user.firstName === 'Clemens').map((user) => user.id).shift(); const roles = await queryInterface.select(null, 'Roles'); const adminRoleId = roles.filter((role) => role.name === 'admin').map((role) => role.id).shift(); const playerRoleId = roles.filter((role) => role.name === 'player').map((role) => role.id).shift(); const coachRoleId = roles.filter((role) => role.name === 'coach').map((role) => role.id).shift(); await queryInterface.bulkInsert('UserRoles', [ { userId: adminUserId, roleId: adminRoleId, createdAt: new Date(), updatedAt: new Date() }, { userId: julianUserId, roleId: playerRoleId, createdAt: new Date(), updatedAt: new Date() }, { userId: clemensUserId, roleId: coachRoleId, createdAt: new Date(), updatedAt: new Date() }, { userId: clemensUserId, roleId: playerRoleId, createdAt: new Date(), updatedAt: new Date() }, ]); }, async down (queryInterface, /*Sequelize*/) { if (process.env.NODE_ENV !== 'production') return; await queryInterface.dropTable('Authentications'); await queryInterface.dropTable('Users'); await queryInterface.dropTable('UserRoles'); } };