mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +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 }) => {
|
||||
const WorkflowStatsModel = this.db.getModel('workflowStats');
|
||||
const [stats, created] = await WorkflowStatsModel.findOrCreate({
|
||||
let stats = await WorkflowStatsModel.findOne({
|
||||
where: { key: model.key },
|
||||
defaults: { key: model.key },
|
||||
transaction,
|
||||
});
|
||||
if (!stats) {
|
||||
stats = await model.createStats({ executed: 0 }, { transaction });
|
||||
}
|
||||
model.stats = stats;
|
||||
model.versionStats = await model.createVersionStats({ id: model.id }, { transaction });
|
||||
if (model.enabled) {
|
||||
|
@ -26,16 +26,21 @@ export default class extends Migration {
|
||||
|
||||
const groupCounts: { [key: string]: { key: string; executed: number } } = {};
|
||||
for (const workflow of workflows) {
|
||||
await WorkflowVersionStatsModel.findOrCreate({
|
||||
const versionStats = await WorkflowVersionStatsModel.findOne({
|
||||
where: {
|
||||
id: workflow.id,
|
||||
},
|
||||
defaults: {
|
||||
id: workflow.id,
|
||||
executed: workflow.get('executed'),
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
if (!versionStats) {
|
||||
await WorkflowVersionStatsModel.create(
|
||||
{
|
||||
id: workflow.id,
|
||||
executed: workflow.get('executed'),
|
||||
},
|
||||
{ transaction },
|
||||
);
|
||||
}
|
||||
|
||||
const key = workflow.get('key');
|
||||
groupCounts[key] = {
|
||||
@ -44,13 +49,15 @@ export default class extends Migration {
|
||||
};
|
||||
}
|
||||
for (const values of Object.values(groupCounts)) {
|
||||
await WorkflowStatsModel.findOrCreate({
|
||||
const stats = await WorkflowStatsModel.findOne({
|
||||
where: {
|
||||
key: values.key,
|
||||
},
|
||||
defaults: values,
|
||||
transaction,
|
||||
});
|
||||
if (!stats) {
|
||||
await WorkflowStatsModel.create(values, { transaction });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user