fix(plugin-fm): add migration to fix attachment ui schema (#2579)

This commit is contained in:
Junyi 2023-08-31 17:38:37 +07:00 committed by GitHub
parent ec3a720aa9
commit ee0d2175b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View File

@ -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<Repository>('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 });
}
});
}
}

View File

@ -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');