mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:06:06 +00:00
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:
parent
c9f51ca416
commit
d8ad98e2f7
@ -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({
|
||||
|
@ -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: {
|
||||
|
Loading…
Reference in New Issue
Block a user