fix(plugin-cm): fix life cycle (#2535)

This commit is contained in:
Junyi 2023-08-25 22:11:12 +07:00 committed by GitHub
parent 3d9a6ef76f
commit 643594abad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 2 deletions

View File

@ -214,7 +214,7 @@ export class CollectionManagerPlugin extends Plugin {
await this.app.db.getRepository<CollectionRepository>('collections').load();
};
this.app.on('afterStart', loadCollections);
this.app.on('beforeStart', loadCollections);
this.app.on('beforeUpgrade', async () => {
const syncOptions = {
alter: {

View File

@ -34,6 +34,8 @@
"@nocobase/database": "0.x",
"@nocobase/evaluators": "0.x",
"@nocobase/logger": "0.x",
"@nocobase/plugin-collection-manager": "0.x",
"@nocobase/plugin-error-handler": "0.x",
"@nocobase/plugin-users": "0.x",
"@nocobase/resourcer": "0.x",
"@nocobase/server": "0.x",

View File

@ -13,7 +13,9 @@ describe('workflow > triggers > collection', () => {
let WorkflowModel;
beforeEach(async () => {
app = await getApp();
app = await getApp({
plugins: ['error-handler', 'collection-manager'],
});
db = app.db;
WorkflowModel = db.getCollection('workflows').model;
@ -50,6 +52,51 @@ describe('workflow > triggers > collection', () => {
const executions = await workflow.getExecutions();
expect(executions.length).toBe(0);
});
it('restart server and listen a collection managed by collection-manager', async () => {
await db.getRepository('collections').create({
values: {
name: 'temp',
title: 'Temp',
},
// to trigger collection sync to db.collections
context: {},
});
const workflow = await WorkflowModel.create({
type: 'collection',
config: {
mode: 1,
collection: 'temp',
},
enabled: true,
});
await db.getRepository('temp').create({ values: {} });
await sleep(500);
const e1 = await workflow.getExecutions();
expect(e1.length).toBe(1);
await app.destroy();
app = await getApp({
plugins: ['error-handler', 'collection-manager'],
database: {
tablePrefix: db.options.tablePrefix,
},
});
db = app.db;
await db.getRepository('temp').create({ values: {} });
await sleep(500);
const e2 = await db.getModel('executions').findAll();
expect(e2.length).toBe(2);
});
});
describe('model context', () => {