From 0ed164ff09d79d1ff2f6d6cb755152d26c1dfa1c Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 22 Sep 2023 16:32:59 +0800 Subject: [PATCH] fix: update or create plugins --- packages/presets/nocobase/src/server/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/presets/nocobase/src/server/index.ts b/packages/presets/nocobase/src/server/index.ts index 6bab45eb6..da20c759d 100644 --- a/packages/presets/nocobase/src/server/index.ts +++ b/packages/presets/nocobase/src/server/index.ts @@ -1,3 +1,4 @@ +import { Repository } from '@nocobase/database'; import { Plugin, PluginManager } from '@nocobase/server'; import _ from 'lodash'; import path from 'path'; @@ -71,7 +72,7 @@ export class PresetNocoBase extends Plugin { }, }); this.app.on('beforeUpgrade', async () => { - await this.createIfNotExists(); + await this.updateOrCreatePlugins(); }); } @@ -91,8 +92,20 @@ export class PresetNocoBase extends Plugin { ); } + async updateOrCreatePlugins() { + const repository = this.app.db.getRepository('applicationPlugins'); + return Promise.all( + this.allPlugins.map((values) => + repository.updateOrCreate({ + values, + filterKeys: ['name'], + }), + ), + ); + } + async createIfNotExists() { - const repository = this.app.db.getRepository('applicationPlugins'); + 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));