Compare commits

...

2 Commits

Author SHA1 Message Date
Flatlogic Bot
0ab882ccde Forced merge: merge ai-dev into master 2026-01-22 11:37:20 +00:00
Flatlogic Bot
f761f5e552 fix permissions 2026-01-22 11:37:12 +00:00

View File

@ -0,0 +1,32 @@
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.
}
};