chore: create sub app db with context (#2891)
This commit is contained in:
parent
5fad821eab
commit
ff22db5e5c
@ -3,11 +3,9 @@ import Application, { AppSupervisor, Gateway, Plugin } from '@nocobase/server';
|
|||||||
import { Mutex } from 'async-mutex';
|
import { Mutex } from 'async-mutex';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import path, { resolve } from 'path';
|
import path, { resolve } from 'path';
|
||||||
import qs from 'qs';
|
|
||||||
import { parse } from 'url';
|
|
||||||
import { ApplicationModel } from '../server';
|
import { ApplicationModel } from '../server';
|
||||||
|
|
||||||
export type AppDbCreator = (app: Application, transaction?: Transactionable) => Promise<void>;
|
export type AppDbCreator = (app: Application, options?: Transactionable & { context?: any }) => Promise<void>;
|
||||||
export type AppOptionsFactory = (appName: string, mainApp: Application) => any;
|
export type AppOptionsFactory = (appName: string, mainApp: Application) => any;
|
||||||
export type SubAppUpgradeHandler = (mainApp: Application) => Promise<void>;
|
export type SubAppUpgradeHandler = (mainApp: Application) => Promise<void>;
|
||||||
|
|
||||||
@ -158,7 +156,9 @@ export class PluginMultiAppManager extends Plugin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// after application created
|
// after application created
|
||||||
this.db.on('applications.afterCreateWithAssociations', async (model: ApplicationModel, options) => {
|
this.db.on(
|
||||||
|
'applications.afterCreateWithAssociations',
|
||||||
|
async (model: ApplicationModel, options: Transactionable & { context?: any }) => {
|
||||||
const { transaction } = options;
|
const { transaction } = options;
|
||||||
|
|
||||||
const subApp = model.registerToSupervisor(this.app, {
|
const subApp = model.registerToSupervisor(this.app, {
|
||||||
@ -166,14 +166,18 @@ export class PluginMultiAppManager extends Plugin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// create database
|
// create database
|
||||||
await this.appDbCreator(subApp, transaction);
|
await this.appDbCreator(subApp, {
|
||||||
|
transaction,
|
||||||
|
context: options.context,
|
||||||
|
});
|
||||||
|
|
||||||
const startPromise = subApp.runAsCLI(['start', '--quickstart'], { from: 'user' });
|
const startPromise = subApp.runAsCLI(['start', '--quickstart'], { from: 'user' });
|
||||||
|
|
||||||
if (options?.context?.waitSubAppInstall) {
|
if (options?.context?.waitSubAppInstall) {
|
||||||
await startPromise;
|
await startPromise;
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
this.db.on('applications.afterDestroy', async (model: ApplicationModel) => {
|
this.db.on('applications.afterDestroy', async (model: ApplicationModel) => {
|
||||||
await AppSupervisor.getInstance().removeApp(model.get('name') as string);
|
await AppSupervisor.getInstance().removeApp(model.get('name') as string);
|
||||||
|
Loading…
Reference in New Issue
Block a user