Compare commits
No commits in common. "0ab882ccde35cf9c1f304d26353ba66532f79079" and "2e9108d8ecf7e6c3405b9ffe57cf10f1326b0237" have entirely different histories.
0ab882ccde
...
2e9108d8ec
@ -1,32 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
async up(queryInterface, Sequelize) {
|
|
||||||
// 1. Ensure the join table exists (idempotent check)
|
|
||||||
await queryInterface.sequelize.query(`
|
|
||||||
CREATE TABLE IF NOT EXISTS "rolesPermissionsPermissions" (
|
|
||||||
"createdAt" timestamp with time zone NOT NULL,
|
|
||||||
"updatedAt" timestamp with time zone NOT NULL,
|
|
||||||
"roles_permissionsId" uuid NOT NULL,
|
|
||||||
"permissionId" uuid NOT NULL,
|
|
||||||
PRIMARY KEY ("roles_permissionsId", "permissionId")
|
|
||||||
);
|
|
||||||
`);
|
|
||||||
|
|
||||||
// 2. Ensure permissions exist (idempotent insert)
|
|
||||||
// We select the IDs of the required permissions and the Public role, then insert into the join table.
|
|
||||||
await queryInterface.sequelize.query(`
|
|
||||||
INSERT INTO "rolesPermissionsPermissions" ("createdAt", "updatedAt", "roles_permissionsId", "permissionId")
|
|
||||||
SELECT NOW(), NOW(), r.id, p.id
|
|
||||||
FROM roles r, permissions p
|
|
||||||
WHERE r.name = 'Public' AND p.name IN ('READ_COURSES', 'READ_USERS', 'READ_CATEGORIES', 'READ_LESSONS')
|
|
||||||
ON CONFLICT ("roles_permissionsId", "permissionId") DO NOTHING;
|
|
||||||
`);
|
|
||||||
},
|
|
||||||
|
|
||||||
async down(queryInterface, Sequelize) {
|
|
||||||
// We generally don't want to remove permissions in a 'fix' migration rollback
|
|
||||||
// as it might inadvertently remove permissions granted by the original migration or manual fixes.
|
|
||||||
// However, strictly speaking, we could reverse the insert.
|
|
||||||
// For safety in this specific context (getting prod to work), we'll leave it empty
|
|
||||||
// or just rely on the previous migration's down logic if needed.
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
x
Reference in New Issue
Block a user