Migration generation order is wrong when using existing fields

Found another issue related to migrations & plugins.

Generated migration code:


  console.log('Delete plugin "Read-only Fields"');
  await client.plugins.destroy('bNeGi2IHRaCsAQQyZPB76g');

  console.log('Install plugin "Read-only Fields"');
  await client.plugins.create({
    id: 'mbq9DrdzRIGqrmwwWJztEg',
    package_name: 'datocms-plugin-readonly-fields',
  });
  await client.plugins.update('mbq9DrdzRIGqrmwwWJztEg', { parameters: { developmentMode: false } });

2 issues in fact:

  • Getting an unexpected validation error for the developmentMode flag

[
  {
    "id": "306dbb",
    "type": "api_error",
    "attributes": {
      "code": "INVALID_FIELD",
      "details": {
        "field": "parameters.developmentMode",
        "code": "VALIDATION_REQUIRED"
      }
    }
  }
]

The generated migration code should set the flags correctly.

  • The first destroy of the existing plugin fails, because itโ€™s used by some fields.
    e.g. if Iโ€™d try to click-delete it, I get an error

Executing the migration, the script simply continues after the failed delete.
It doesnโ€™t check if delete was successful and we end up with the same plugin twice.

Should I move this to a separate thread?

The cause is actually related to Bug: Autogenerating and running migrations tries to generate schema_migration model twice - #9 by ldc
but the unintended behavior seems to show 2 unrelated bugs.