diff --git a/packages/plugins/file-manager/src/server/migrations/20230831160742-fix-attachment-field.ts b/packages/plugins/file-manager/src/server/migrations/20230831160742-fix-attachment-field.ts new file mode 100644 index 0000000000..2e2ed12891 --- /dev/null +++ b/packages/plugins/file-manager/src/server/migrations/20230831160742-fix-attachment-field.ts @@ -0,0 +1,42 @@ +import { Migration } from '@nocobase/server'; +import { Op, Repository } from '@nocobase/database'; + +export default class extends Migration { + async up() { + const result = await this.app.version.satisfies('<0.13.0-alpha.5'); + + if (!result) { + return; + } + + const r = this.db.getRepository('uiSchemas'); + const items = await r.find({ + filter: { + 'schema.x-component': 'CollectionField', + 'schema.x-component-props.action': { + [Op.like]: '%:create?attachementField%', + }, + }, + }); + console.log(items?.length); + + 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; + } + schema['x-component-props'].action = schema['x-component-props'].action.replace( + 'attachementField', + 'attachmentField', + ); + item.set('schema', schema); + await item.save({ transaction }); + } + }); + } +} diff --git a/packages/plugins/file-manager/src/server/server.ts b/packages/plugins/file-manager/src/server/server.ts index fcc24f50bc..f7b1d46cef 100644 --- a/packages/plugins/file-manager/src/server/server.ts +++ b/packages/plugins/file-manager/src/server/server.ts @@ -42,6 +42,14 @@ export default class PluginFileManager extends Plugin { actions: ['storages:*'], }); + this.db.addMigrations({ + namespace: 'file-manager', + directory: resolve(__dirname, 'migrations'), + context: { + plugin: this, + }, + }); + initActions(this); this.app.acl.allow('attachments', 'upload', 'loggedIn');