mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
fix(plugin-workflow): fix migration (#6667)
* fix(plugin-workflow): fix migration * fix(plugin-workflow): change findOrCreate to simple logic
This commit is contained in:
parent
9199061c5a
commit
bc519a118c
@ -115,11 +115,13 @@ export default class PluginWorkflowServer extends Plugin {
|
|||||||
|
|
||||||
private onAfterCreate = async (model: WorkflowModel, { transaction }) => {
|
private onAfterCreate = async (model: WorkflowModel, { transaction }) => {
|
||||||
const WorkflowStatsModel = this.db.getModel('workflowStats');
|
const WorkflowStatsModel = this.db.getModel('workflowStats');
|
||||||
const [stats, created] = await WorkflowStatsModel.findOrCreate({
|
let stats = await WorkflowStatsModel.findOne({
|
||||||
where: { key: model.key },
|
where: { key: model.key },
|
||||||
defaults: { key: model.key },
|
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
if (!stats) {
|
||||||
|
stats = await model.createStats({ executed: 0 }, { transaction });
|
||||||
|
}
|
||||||
model.stats = stats;
|
model.stats = stats;
|
||||||
model.versionStats = await model.createVersionStats({ id: model.id }, { transaction });
|
model.versionStats = await model.createVersionStats({ id: model.id }, { transaction });
|
||||||
if (model.enabled) {
|
if (model.enabled) {
|
||||||
|
@ -26,16 +26,21 @@ export default class extends Migration {
|
|||||||
|
|
||||||
const groupCounts: { [key: string]: { key: string; executed: number } } = {};
|
const groupCounts: { [key: string]: { key: string; executed: number } } = {};
|
||||||
for (const workflow of workflows) {
|
for (const workflow of workflows) {
|
||||||
await WorkflowVersionStatsModel.findOrCreate({
|
const versionStats = await WorkflowVersionStatsModel.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: workflow.id,
|
id: workflow.id,
|
||||||
},
|
},
|
||||||
defaults: {
|
transaction,
|
||||||
|
});
|
||||||
|
if (!versionStats) {
|
||||||
|
await WorkflowVersionStatsModel.create(
|
||||||
|
{
|
||||||
id: workflow.id,
|
id: workflow.id,
|
||||||
executed: workflow.get('executed'),
|
executed: workflow.get('executed'),
|
||||||
},
|
},
|
||||||
transaction,
|
{ transaction },
|
||||||
});
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const key = workflow.get('key');
|
const key = workflow.get('key');
|
||||||
groupCounts[key] = {
|
groupCounts[key] = {
|
||||||
@ -44,13 +49,15 @@ export default class extends Migration {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
for (const values of Object.values(groupCounts)) {
|
for (const values of Object.values(groupCounts)) {
|
||||||
await WorkflowStatsModel.findOrCreate({
|
const stats = await WorkflowStatsModel.findOne({
|
||||||
where: {
|
where: {
|
||||||
key: values.key,
|
key: values.key,
|
||||||
},
|
},
|
||||||
defaults: values,
|
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
if (!stats) {
|
||||||
|
await WorkflowStatsModel.create(values, { transaction });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user