From 43e52843fa7f0dcf483b2c7b081cfa279a816d27 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Sat, 18 Feb 2023 09:27:54 +0800 Subject: [PATCH] fix: add schema (#1464) * fix: add schema * chore: format --- packages/core/database/src/database-utils/index.ts | 4 ++-- packages/core/database/src/database.ts | 5 +++-- packages/core/server/src/app-manager.ts | 3 ++- packages/plugins/collection-manager/src/server.ts | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/database/src/database-utils/index.ts b/packages/core/database/src/database-utils/index.ts index 513ba1d3f..8e2d656c8 100644 --- a/packages/core/database/src/database-utils/index.ts +++ b/packages/core/database/src/database-utils/index.ts @@ -5,7 +5,7 @@ export default class DatabaseUtils { constructor(public db: Database) {} addSchema(tableName, schema?) { - if (this.db.options.schema) { + if (this.db.options.schema && !schema) { schema = this.db.options.schema; } @@ -13,7 +13,7 @@ export default class DatabaseUtils { // @ts-ignore tableName = this.db.sequelize.getQueryInterface().queryGenerator.addSchema({ tableName, - _schema: this.db.options.schema, + _schema: schema, }); } diff --git a/packages/core/database/src/database.ts b/packages/core/database/src/database.ts index 1f9b2f024..625186df2 100644 --- a/packages/core/database/src/database.ts +++ b/packages/core/database/src/database.ts @@ -15,7 +15,7 @@ import { Sequelize, SyncOptions, Transactionable, - Utils + Utils, } from 'sequelize'; import { SequelizeStorage, Umzug } from 'umzug'; import { Collection, CollectionOptions, RepositoryType } from './collection'; @@ -58,7 +58,7 @@ import { SyncListener, UpdateListener, UpdateWithAssociationsListener, - ValidateListener + ValidateListener, } from './types'; import { patchSequelizeQueryInterface, snakeCase } from './utils'; @@ -174,6 +174,7 @@ export class Database extends EventEmitter implements AsyncEmitter { constructor(options: DatabaseOptions) { super(); + this.version = new DatabaseVersion(this); const opts = { diff --git a/packages/core/server/src/app-manager.ts b/packages/core/server/src/app-manager.ts index 67f85ba85..65b1a1ded 100644 --- a/packages/core/server/src/app-manager.ts +++ b/packages/core/server/src/app-manager.ts @@ -52,10 +52,11 @@ export class AppManager extends EventEmitter { return server.listen(...args); } - async getApplication(appName: string): Promise { + async getApplication(appName: string, options = {}): Promise { await this.emitAsync('beforeGetApplication', { appManager: this, name: appName, + options, }); return this.applications.get(appName); diff --git a/packages/plugins/collection-manager/src/server.ts b/packages/plugins/collection-manager/src/server.ts index 0c064edd5..54c9fb068 100644 --- a/packages/plugins/collection-manager/src/server.ts +++ b/packages/plugins/collection-manager/src/server.ts @@ -14,7 +14,7 @@ import { beforeCreateForChildrenCollection, beforeCreateForReverseField, beforeDestroyForeignKey, - beforeInitOptions + beforeInitOptions, } from './hooks'; import { InheritedCollection } from '@nocobase/database';