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() } ]); const auths = await queryInterface.select(null, 'Authentications'); const adminAuthId = auths.filter((auth) => auth.email === 'admin@example.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(), }] ); const users = await queryInterface.select(null, 'Users'); const adminUserId = users.filter((user) => user.firstName === 'Admin').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(); await queryInterface.bulkInsert('UserRoles', [ { userId: adminUserId, roleId: adminRoleId, 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'); } };