From d15eab22943c7912928acbfb8295a1615f972a36 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Tue, 30 Apr 2024 15:38:32 +0800 Subject: [PATCH] fix: upgrade sub app (#4246) --- .../server/__tests__/multiple-apps.test.ts | 39 ++++++++++++++++++- .../src/server/server.ts | 10 ++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/__tests__/multiple-apps.test.ts b/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/__tests__/multiple-apps.test.ts index 2eb2ebb229..1f66d96453 100644 --- a/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/__tests__/multiple-apps.test.ts +++ b/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/__tests__/multiple-apps.test.ts @@ -13,7 +13,7 @@ describe('multiple apps', () => { beforeEach(async () => { app = await createMockServer({ - plugins: ['multi-app-manager'], + plugins: ['nocobase', 'multi-app-manager'], }); db = app.db; }); @@ -94,6 +94,43 @@ describe('multiple apps', () => { expect(subAppStatus).toEqual('running'); }); + it('should upgrade sub app', async () => { + await db.getRepository('applications').create({ + values: { + name: 'test1', + options: { + plugins: ['nocobase'], + }, + }, + context: { + waitSubAppInstall: true, + }, + }); + + await db.getRepository('applications').create({ + values: { + name: 'test2', + options: { + plugins: ['nocobase'], + }, + }, + context: { + waitSubAppInstall: true, + }, + }); + + await app.runCommand('restart'); + await app.runCommand('upgrade'); + // const subAppStatus = AppSupervisor.getInstance().getAppStatus(name); + // expect(subAppStatus).toEqual('running'); + // + // const subApp = await AppSupervisor.getInstance().getApp(name); + // await subApp.runCommand('upgrade'); + // + // await AppSupervisor.getInstance().removeApp(name); + // expect(await db.getRepository('applications').count()).toBe(1); + }); + it('should list application with status', async () => { const sub1 = `td_${uid()}`; await db.getRepository('applications').create({ diff --git a/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/server.ts b/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/server.ts index 3839f0473a..c689d0af2a 100644 --- a/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/server.ts +++ b/packages/plugins/@nocobase/plugin-multi-app-manager/src/server/server.ts @@ -36,11 +36,8 @@ const defaultSubAppUpgradeHandle: SubAppUpgradeHandler = async (mainApp: Applica upgrading: true, }); - console.log({ beforeSubAppStatus }); try { mainApp.setMaintainingMessage(`upgrading sub app ${instance.name}...`); - console.log(`${instance.name}: upgrading...`); - await subApp.runAsCLI(['upgrade'], { from: 'user' }); if (!beforeSubAppStatus && AppSupervisor.getInstance().getAppStatus(instance.name) === 'initialized') { await AppSupervisor.getInstance().removeApp(instance.name); @@ -204,7 +201,8 @@ export class PluginMultiAppManagerServer extends Plugin { return; } - const applicationRecord = (await self.app.db.getRepository('applications').findOne({ + const mainApp = await appSupervisor.getApp('main'); + const applicationRecord = (await mainApp.db.getRepository('applications').findOne({ filter: { name, }, @@ -224,7 +222,7 @@ export class PluginMultiAppManagerServer extends Plugin { return; } - const subApp = applicationRecord.registerToSupervisor(self.app, { + const subApp = applicationRecord.registerToSupervisor(mainApp, { appOptionsFactory: self.appOptionsFactory, }); @@ -234,7 +232,7 @@ export class PluginMultiAppManagerServer extends Plugin { } } - AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication); + AppSupervisor.getInstance().setAppBootstrapper(LazyLoadApplication.bind(this)); Gateway.getInstance().addAppSelectorMiddleware(async (ctx, next) => { const { req } = ctx;