48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
module.exports = {
|
|
async up(queryInterface, Sequelize) {
|
|
const [roles] = await queryInterface.sequelize.query(
|
|
`SELECT id FROM "roles" WHERE name = 'Public' LIMIT 1;`
|
|
);
|
|
const [readProductsPerm] = await queryInterface.sequelize.query(
|
|
`SELECT id FROM "permissions" WHERE name = 'READ_PRODUCTS' LIMIT 1;`
|
|
);
|
|
const [readCategoriesPerm] = await queryInterface.sequelize.query(
|
|
`SELECT id FROM "permissions" WHERE name = 'READ_CATEGORIES' LIMIT 1;`
|
|
);
|
|
|
|
if (roles.length && readProductsPerm.length) {
|
|
const [existing] = await queryInterface.sequelize.query(
|
|
`SELECT * FROM "rolesPermissionsPermissions" WHERE "roles_permissionsId" = '${roles[0].id}' AND "permissionId" = '${readProductsPerm[0].id}';`
|
|
);
|
|
if (!existing.length) {
|
|
await queryInterface.bulkInsert('rolesPermissionsPermissions', [
|
|
{
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
roles_permissionsId: roles[0].id,
|
|
permissionId: readProductsPerm[0].id,
|
|
},
|
|
]);
|
|
}
|
|
}
|
|
|
|
if (roles.length && readCategoriesPerm.length) {
|
|
const [existing] = await queryInterface.sequelize.query(
|
|
`SELECT * FROM "rolesPermissionsPermissions" WHERE "roles_permissionsId" = '${roles[0].id}' AND "permissionId" = '${readCategoriesPerm[0].id}';`
|
|
);
|
|
if (!existing.length) {
|
|
await queryInterface.bulkInsert('rolesPermissionsPermissions', [
|
|
{
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
roles_permissionsId: roles[0].id,
|
|
permissionId: readCategoriesPerm[0].id,
|
|
},
|
|
]);
|
|
}
|
|
}
|
|
},
|
|
|
|
async down(queryInterface, Sequelize) {
|
|
}
|
|
}; |