mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 22:49:26 +08:00
* fix(plugin-workflow): fix migration * fix(plugin-workflow): fix migration * fix(plugin-workflow): change migration name to trigger
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { Migration } from '@nocobase/server';
|
|
|
|
|
|
|
|
const calculatorsMap = {
|
|
'equal': '==',
|
|
'===': '==',
|
|
'notEqual': '!=',
|
|
'!==': '!=',
|
|
'gt': '>',
|
|
'gte': '>=',
|
|
'lt': '<',
|
|
'lte': '<=',
|
|
includes(a, b) {
|
|
return `SEARCH('${b}', '${a}') >= 0`;
|
|
},
|
|
notIncludes(a, b) {
|
|
return `SEARCH('${b}', '${a}') < 0`;
|
|
},
|
|
startsWith(a, b) {
|
|
return `SEARCH('${b}', '${a}') == 0`
|
|
},
|
|
endsWith(a, b) {
|
|
return `RIGHT('${a}', LEN('${b}')) == '${b}'`;
|
|
},
|
|
notStartsWith(a, b) {
|
|
return `SEARCH('${b}', '${a}') != 0`;
|
|
},
|
|
notEndsWith(a, b) {
|
|
return `RIGHT('${a}', LEN('${b}')) != '${b}'`;
|
|
},
|
|
}
|
|
|
|
function migrateConfig({ group: { type = 'and', calculations = [] } }) {
|
|
return {
|
|
group: {
|
|
type,
|
|
calculations: calculations.map(({ calculator = '===', operands = [] }: any) => {
|
|
return `(${operands.map((operand) => operand?.group ? migrateConfig(operand) : operand).join(` ${calculatorsMap[calculator]} `)})`;
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
export default class extends Migration {
|
|
async up() {
|
|
const match = await this.app.version.satisfies('<0.9.0-alpha.3');
|
|
if (!match) {
|
|
return;
|
|
}
|
|
|
|
const NodeRepo = this.context.db.getRepository('flow_nodes');
|
|
await this.context.db.sequelize.transaction(async (transaction) => {
|
|
const nodes = await NodeRepo.find({
|
|
filter: {
|
|
type: 'condition'
|
|
},
|
|
transaction
|
|
});
|
|
console.log('%d nodes need to be migrated.', nodes.length);
|
|
|
|
await nodes.reduce((promise, node) => promise.then(() => {
|
|
return node.update({
|
|
config: {
|
|
...node.config,
|
|
engine: 'basic',
|
|
// calculation: migrateConfig(node.config.calculation)
|
|
}
|
|
}, {
|
|
transaction
|
|
});
|
|
}), Promise.resolve());
|
|
});
|
|
}
|
|
}
|