0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/schemas/alterations/1.0.0_rc.0-1673863835-ac-scope-role.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-03-16 06:04:55 -05:00
import { sql } from '@silverhand/slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
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
2023-02-02 05:36:18 -05:00
where id = ${adminConsoleAdminRoleId}
`);
if (!newRole) {
await pool.query(sql`
update roles
2023-02-02 05:36:18 -05:00
set id = ${adminConsoleAdminRoleId}
where name = ${adminRoleName}
`);
}
// Fix scope role
const relation = await pool.maybeOne(sql`
select * from roles_scopes
2023-02-02 05:36:18 -05:00
where scope_id = ${managementResourceScopeId}
and role_id = ${adminConsoleAdminRoleId}
`);
if (!relation) {
await pool.query(sql`
insert into roles_scopes
2023-02-02 05:36:18 -05:00
(role_id, scope_id)
values (${adminConsoleAdminRoleId}, ${managementResourceScopeId})
`);
}
},
down: async () => {
// This is a hotfix for seed, down script is not needed
},
};
export default alteration;