From c65507606a670d5e2eb2bff97d5a43f75cd85fdf Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 28 Aug 2023 00:18:46 +0800 Subject: [PATCH] fix: plugin list not updated after upgrade (#2545) --- packages/presets/nocobase/src/server/index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/presets/nocobase/src/server/index.ts b/packages/presets/nocobase/src/server/index.ts index 4cbe3735d..03c2efc7b 100644 --- a/packages/presets/nocobase/src/server/index.ts +++ b/packages/presets/nocobase/src/server/index.ts @@ -69,6 +69,9 @@ export class PresetNocoBase extends Plugin { plugin: this, }, }); + this.app.on('beforeUpgrade', async () => { + await this.createIfNotExist(); + }); } get allPlugins() { @@ -79,6 +82,14 @@ export class PresetNocoBase extends Plugin { .concat(this.localPlugins.map((name) => ({ name }))); } + async createIfNotExist() { + const repository = this.app.db.getRepository('applicationPlugins'); + const existPlugins = await repository.find(); + const existPluginNames = existPlugins.map((item) => item.name); + const plugins = this.allPlugins.filter((item) => !existPluginNames.includes(item.name)); + await repository.create({ values: plugins }); + } + async install() { const repository = this.app.db.getRepository('applicationPlugins'); const existPlugins = await repository.find();