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));