Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
539cf4abba |
@ -0,0 +1,41 @@
|
|||||||
|
module.exports = {
|
||||||
|
async up(queryInterface, Sequelize) {
|
||||||
|
const createdAt = new Date();
|
||||||
|
const updatedAt = new Date();
|
||||||
|
|
||||||
|
const [roles] = await queryInterface.sequelize.query(
|
||||||
|
`SELECT id FROM "roles" WHERE name = 'Public' LIMIT 1;`
|
||||||
|
);
|
||||||
|
const publicRoleId = roles[0]?.id;
|
||||||
|
|
||||||
|
if (!publicRoleId) return;
|
||||||
|
|
||||||
|
const [permissions] = await queryInterface.sequelize.query(
|
||||||
|
`SELECT id, name FROM "permissions" WHERE name IN ('READ_CASINO_HOTELS', 'READ_AMENITIES');`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (permissions.length === 0) return;
|
||||||
|
|
||||||
|
const rolePermissions = permissions.map(p => ({
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
roles_permissionsId: publicRoleId,
|
||||||
|
permissionId: p.id
|
||||||
|
}));
|
||||||
|
|
||||||
|
await queryInterface.bulkInsert('rolesPermissionsPermissions', rolePermissions);
|
||||||
|
},
|
||||||
|
|
||||||
|
async down(queryInterface, Sequelize) {
|
||||||
|
const [roles] = await queryInterface.sequelize.query(
|
||||||
|
`SELECT id FROM "roles" WHERE name = 'Public' LIMIT 1;`
|
||||||
|
);
|
||||||
|
const publicRoleId = roles[0]?.id;
|
||||||
|
|
||||||
|
if (!publicRoleId) return;
|
||||||
|
|
||||||
|
await queryInterface.sequelize.query(
|
||||||
|
`DELETE FROM "rolesPermissionsPermissions" WHERE "roles_permissionsId" = '${publicRoleId}';`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user