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;
|
public schema: string;
|
||||||
|
|
||||||
async beforeLoad() {
|
async beforeLoad() {
|
||||||
if (process.env.COLLECTION_MANAGER_SCHEMA) {
|
if (this.app.db.inDialect('postgres')) {
|
||||||
this.schema = process.env.COLLECTION_MANAGER_SCHEMA;
|
this.schema = process.env.COLLECTION_MANAGER_SCHEMA || this.db.options.schema || 'public';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.db.registerModels({
|
this.app.db.registerModels({
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { BelongsToManyRepository, Database } from '@nocobase/database';
|
import { BelongsToManyRepository, Database } from '@nocobase/database';
|
||||||
import { MockServer, mockServer, pgOnly } from '@nocobase/test';
|
import { MockServer, mockServer, pgOnly } from '@nocobase/test';
|
||||||
|
import * as process from 'process';
|
||||||
|
|
||||||
pgOnly()('enable plugin', () => {
|
pgOnly()('enable plugin', () => {
|
||||||
let mainDb: Database;
|
let mainDb: Database;
|
||||||
@ -255,6 +256,30 @@ pgOnly()('collection sync', () => {
|
|||||||
expect(user).toBeTruthy();
|
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 () => {
|
it('should support syncToApps with wildcard value', async () => {
|
||||||
const subApp1Record = await mainDb.getRepository('applications').create({
|
const subApp1Record = await mainDb.getRepository('applications').create({
|
||||||
values: {
|
values: {
|
||||||
|
Loading…
Reference in New Issue
Block a user