fix(collection-manager): share collection when COLLECTION_MANAGER_SCHEMA not set (#2081)

* fix: share collection when COLLECTION_MANAGER_SCHEMA not set

* fix: test
This commit is contained in:
ChengLei Shao 2023-06-20 11:28:54 +08:00 committed by GitHub
parent c9f51ca416
commit d8ad98e2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -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({

View File

@ -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: {