fix(plugin-fm): add migration to fix attachment ui schema (#2579)
This commit is contained in:
		
							parent
							
								
									ec3a720aa9
								
							
						
					
					
						commit
						ee0d2175b8
					
				@ -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 });
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -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');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user