2023-01-16 02:45:47 -05:00
|
|
|
import { sql } from 'slonik';
|
|
|
|
|
|
|
|
import type { AlterationScript } from '../lib/types/alteration.js';
|
|
|
|
|
|
|
|
const managementResourceScopeId = 'management-api-scope';
|
|
|
|
const managementResourceId = 'management-api';
|
|
|
|
const managementResourceScope = Object.freeze({
|
|
|
|
id: managementResourceScopeId,
|
|
|
|
name: 'management-api:default',
|
|
|
|
description: 'Default scope for management API',
|
|
|
|
resourceId: managementResourceId,
|
|
|
|
});
|
|
|
|
|
|
|
|
const alteration: AlterationScript = {
|
|
|
|
up: async (pool) => {
|
|
|
|
const scope = await pool.maybeOne(sql`
|
|
|
|
select * from scopes where id =${managementResourceScopeId}
|
|
|
|
`);
|
|
|
|
|
|
|
|
if (!scope) {
|
|
|
|
await pool.query(sql`
|
|
|
|
insert into scopes
|
|
|
|
(id, name, description, resource_id)
|
|
|
|
values (${managementResourceScope.id}, ${managementResourceScope.name}, ${managementResourceScope.description}, ${managementResourceScope.resourceId})
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
},
|
2023-02-02 05:36:18 -05:00
|
|
|
down: async (pool) => {
|
|
|
|
await pool.query(sql`
|
|
|
|
delete from scopes where id = ${managementResourceScope.id};
|
|
|
|
`);
|
2023-01-16 02:45:47 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default alteration;
|