mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:55:50 +00:00
chore: merge sub app database options (#3640)
This commit is contained in:
parent
b6d17853d8
commit
599a1aa0c6
@ -1,6 +1,6 @@
|
||||
import { Database } from '@nocobase/database';
|
||||
import { AppSupervisor, Gateway } from '@nocobase/server';
|
||||
import { MockServer, createMockServer } from '@nocobase/test';
|
||||
import { createMockServer, MockServer } from '@nocobase/test';
|
||||
import { uid } from '@nocobase/utils';
|
||||
import { vi } from 'vitest';
|
||||
import { PluginMultiAppManager } from '../server';
|
||||
@ -22,6 +22,29 @@ describe('multiple apps', () => {
|
||||
await app.destroy();
|
||||
});
|
||||
|
||||
it('should merge database options', async () => {
|
||||
const name = `td_${uid()}`;
|
||||
|
||||
await db.getRepository('applications').create({
|
||||
values: {
|
||||
name,
|
||||
options: {
|
||||
plugins: [],
|
||||
database: {
|
||||
underscored: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
context: {
|
||||
waitSubAppInstall: true,
|
||||
},
|
||||
});
|
||||
|
||||
const subApp = await AppSupervisor.getInstance().getApp(name);
|
||||
|
||||
expect(subApp.db.options.underscored).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should register db creator', async () => {
|
||||
const fn = vi.fn();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Model, Transactionable } from '@nocobase/database';
|
||||
import { Application } from '@nocobase/server';
|
||||
import { AppOptionsFactory } from '../server';
|
||||
import { merge } from '@nocobase/utils';
|
||||
|
||||
export interface registerAppOptions extends Transactionable {
|
||||
skipInstall?: boolean;
|
||||
@ -10,11 +11,12 @@ export interface registerAppOptions extends Transactionable {
|
||||
export class ApplicationModel extends Model {
|
||||
registerToSupervisor(mainApp: Application, options: registerAppOptions) {
|
||||
const appName = this.get('name') as string;
|
||||
const appOptions = (this.get('options') as any) || {};
|
||||
const appModelOptions = (this.get('options') as any) || {};
|
||||
|
||||
const appOptions = options.appOptionsFactory(appName, mainApp);
|
||||
|
||||
const subAppOptions = {
|
||||
...options.appOptionsFactory(appName, mainApp),
|
||||
...appOptions,
|
||||
...(merge(appOptions, appModelOptions) as object),
|
||||
name: appName,
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { Database, IDatabaseOptions, Transactionable } from '@nocobase/database';
|
||||
import Application, { AppSupervisor, Gateway, Plugin } from '@nocobase/server';
|
||||
import { Mutex } from 'async-mutex';
|
||||
import lodash from 'lodash';
|
||||
import path from 'path';
|
||||
import { ApplicationModel } from '../server';
|
||||
@ -125,8 +124,6 @@ export class PluginMultiAppManager extends Plugin {
|
||||
appOptionsFactory: AppOptionsFactory = defaultAppOptionsFactory;
|
||||
subAppUpgradeHandler: SubAppUpgradeHandler = defaultSubAppUpgradeHandle;
|
||||
|
||||
private beforeGetApplicationMutex = new Mutex();
|
||||
|
||||
static getDatabaseConfig(app: Application): IDatabaseOptions {
|
||||
let oldConfig =
|
||||
app.options.database instanceof Database
|
||||
@ -136,6 +133,7 @@ export class PluginMultiAppManager extends Plugin {
|
||||
if (!oldConfig && app.db) {
|
||||
oldConfig = app.db.options;
|
||||
}
|
||||
|
||||
return lodash.cloneDeep(lodash.omit(oldConfig, ['migrator']));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user