diff --git a/packages/schemas/alterations/next-1673863835-ac-scope-role.ts b/packages/schemas/alterations/next-1673863835-ac-scope-role.ts index 203b5ac69..f260b8c61 100644 --- a/packages/schemas/alterations/next-1673863835-ac-scope-role.ts +++ b/packages/schemas/alterations/next-1673863835-ac-scope-role.ts @@ -2,11 +2,27 @@ import { sql } from 'slonik'; import type { AlterationScript } from '../lib/types/alteration.js'; -const managementResourceScopeId = 'management-api-scope'; const adminConsoleAdminRoleId = 'ac-admin-id'; +const adminRoleName = 'admin'; +const managementResourceScopeId = 'management-api-scope'; const alteration: AlterationScript = { up: async (pool) => { + // Fix role id + const newRole = await pool.maybeOne(sql` + select * from roles + where id = ${adminConsoleAdminRoleId} + `); + + if (!newRole) { + await pool.query(sql` + update roles + set id = ${adminConsoleAdminRoleId} + where name = ${adminRoleName} + `); + } + + // Fix scope role const relation = await pool.maybeOne(sql` select * from roles_scopes where scope_id = ${managementResourceScopeId}