From d559937e8b69bc1092b8c8de5fded271a4c0d628 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Mon, 16 Jan 2023 15:45:47 +0800 Subject: [PATCH] fix(schemas): add alteration for default ac scope (#2953) --- .../next-1673853579-ac-default-scope.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 packages/schemas/alterations/next-1673853579-ac-default-scope.ts diff --git a/packages/schemas/alterations/next-1673853579-ac-default-scope.ts b/packages/schemas/alterations/next-1673853579-ac-default-scope.ts new file mode 100644 index 000000000..a8524c423 --- /dev/null +++ b/packages/schemas/alterations/next-1673853579-ac-default-scope.ts @@ -0,0 +1,33 @@ +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}) + `); + } + }, + down: async () => { + // This is a hotfix for seed, down script is not needed + }, +}; + +export default alteration;