From fdb03288381f2e09ca6f12afbf075dedfec1ddc0 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 9 May 2023 15:45:36 +0800 Subject: [PATCH] fix: add migration --- .../20230509214649-association-select.ts | 39 +++++++++++++++++++ .../plugins/ui-schema-storage/src/server.ts | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/plugins/ui-schema-storage/src/migrations/20230509214649-association-select.ts diff --git a/packages/plugins/ui-schema-storage/src/migrations/20230509214649-association-select.ts b/packages/plugins/ui-schema-storage/src/migrations/20230509214649-association-select.ts new file mode 100644 index 0000000000..3618292b24 --- /dev/null +++ b/packages/plugins/ui-schema-storage/src/migrations/20230509214649-association-select.ts @@ -0,0 +1,39 @@ +import { Migration } from '@nocobase/server'; + +export default class extends Migration { + async up() { + const result = await this.app.version.satisfies('<0.9.2-alpha.5'); + if (!result) { + return; + } + const r = this.db.getRepository('uiSchemas'); + const items = await r.find({ + filter: { + 'schema.x-designer': 'AssociationSelect.Designer', + }, + }); + await this.db.sequelize.transaction(async (transaction) => { + for (const item of items) { + const schema = item.schema; + if (!schema['x-collection-field']) { + continue; + } + const field = this.db.getFieldByPath(schema['x-collection-field']); + if (!field) { + continue; + } + if (['hasOne', 'belongsTo'].includes(field.type)) { + schema['type'] = 'object'; + } else if (['hasMany', 'belongsToMany'].includes(field.type)) { + schema['type'] = 'array'; + } else { + continue; + } + schema['x-designer'] = 'FormItem.Designer'; + schema['x-component'] = 'CollectionField'; + item.set('schema', schema); + await item.save({ transaction }); + } + }); + } +} diff --git a/packages/plugins/ui-schema-storage/src/server.ts b/packages/plugins/ui-schema-storage/src/server.ts index 8045cbfb57..64fa4f3723 100644 --- a/packages/plugins/ui-schema-storage/src/server.ts +++ b/packages/plugins/ui-schema-storage/src/server.ts @@ -90,7 +90,7 @@ export class UiSchemaStoragePlugin extends Plugin { async load() { this.db.addMigrations({ - namespace: 'collection-manager', + namespace: 'ui-schema-storage', directory: path.resolve(__dirname, './migrations'), context: { plugin: this,