diff --git a/packages/plugins/collection-manager/src/server.ts b/packages/plugins/collection-manager/src/server.ts index b4a6d695a..3f655b856 100644 --- a/packages/plugins/collection-manager/src/server.ts +++ b/packages/plugins/collection-manager/src/server.ts @@ -27,8 +27,8 @@ export class CollectionManagerPlugin extends Plugin { public schema: string; async beforeLoad() { - if (process.env.COLLECTION_MANAGER_SCHEMA) { - this.schema = process.env.COLLECTION_MANAGER_SCHEMA; + if (this.app.db.inDialect('postgres')) { + this.schema = process.env.COLLECTION_MANAGER_SCHEMA || this.db.options.schema || 'public'; } this.app.db.registerModels({ diff --git a/packages/plugins/multi-app-share-collection/src/server/__tests__/collection-sync.test.ts b/packages/plugins/multi-app-share-collection/src/server/__tests__/collection-sync.test.ts index dfd01692b..8846af73f 100644 --- a/packages/plugins/multi-app-share-collection/src/server/__tests__/collection-sync.test.ts +++ b/packages/plugins/multi-app-share-collection/src/server/__tests__/collection-sync.test.ts @@ -1,5 +1,6 @@ import { BelongsToManyRepository, Database } from '@nocobase/database'; import { MockServer, mockServer, pgOnly } from '@nocobase/test'; +import * as process from 'process'; pgOnly()('enable plugin', () => { let mainDb: Database; @@ -255,6 +256,30 @@ pgOnly()('collection sync', () => { expect(user).toBeTruthy(); }); + it('should sync custom collections', async () => { + const subApp1Record = await mainDb.getRepository('applications').create({ + values: { + name: 'sub1', + }, + }); + + const subApp1 = await mainApp.appManager.getApplication(subApp1Record.name); + + await mainApp.db.getRepository('collections').create({ + values: { + name: 'posts', + fields: [{ type: 'string', title: 'title' }], + }, + context: {}, + }); + + const postCollection = subApp1.db.getCollection('posts'); + + expect(postCollection.options.schema).toBe( + process.env.COLLECTION_MANAGER_SCHEMA || mainDb.options.schema || 'public', + ); + }); + it('should support syncToApps with wildcard value', async () => { const subApp1Record = await mainDb.getRepository('applications').create({ values: {