* fix: observer * refactor(plugin-formula): merge 2 formula field type * fix(plugin-formula): fix types * fix(plugin-formula): fix type * fix(plugin-formula): fix formulajs version * fix(plugin-formula): change to VariableInput to avoid range error * test(plugin-formula): add test * fix(plugin-formula): fix test case * fix(plugin-formula): fix test case * fix(plugin-formula): fix test case * refactor(plugin-formula): move components into plugin * fix(plugin-formula): fix migration * fix(plugin-formula): revert legacy component to fix build * fix(plugin-formula): fix test case * fix(plugin-formula): fix test case * fix(plugin-formula): fix read-pretty component * fix(plugin-formula): fix formula result component * feat(plugin-formula): add checkbox display X --------- Co-authored-by: chenos <chenlinxh@gmail.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { Migration } from '@nocobase/server';
|
|
|
|
export default class extends Migration {
|
|
async up() {
|
|
const result = await this.app.version.satisfies('<=0.9.0-alpha.2');
|
|
if (!result) {
|
|
return;
|
|
}
|
|
const { db } = this.context;
|
|
await db.sequelize.transaction(async (transaction) => {
|
|
const Field = db.getRepository('fields');
|
|
const fields = await Field.find({ transaction });
|
|
for (const field of fields) {
|
|
if (['mathFormula', 'excelFormula'].includes(field.get('type'))) {
|
|
const { options } = field;
|
|
field.set({
|
|
type: 'formula',
|
|
interface: 'formula',
|
|
options: {
|
|
...options,
|
|
engine: field.get('type') === 'mathFormula' ? 'math.js' : 'formula.js',
|
|
dataType: options.dataType === 'number' ? 'double' : 'string'
|
|
},
|
|
});
|
|
await field.save({ transaction });
|
|
const schema = await field.getUiSchema({ transaction });
|
|
schema.set('x-component', 'Formula.Result');
|
|
await schema.save({ transaction });
|
|
}
|
|
}
|
|
|
|
const AppPlugin = db.getRepository('applicationPlugins');
|
|
const formulaPlugin = await AppPlugin.findOne({
|
|
filter: {
|
|
name: 'formula-field',
|
|
},
|
|
transaction
|
|
});
|
|
|
|
if (!formulaPlugin) {
|
|
await AppPlugin.create({
|
|
values: {
|
|
name: 'formula-field',
|
|
version: '0.9.0-alpha.2',
|
|
enabled: true,
|
|
installed: true,
|
|
builtin: true
|
|
},
|
|
transaction
|
|
});
|
|
}
|
|
|
|
await AppPlugin.destroy({
|
|
filter: {
|
|
name: ['math-formula-field', 'excel-formula-field']
|
|
},
|
|
transaction
|
|
});
|
|
});
|
|
}
|
|
}
|