watermarkchurch/contentful-schema-diff

Migration of ID change is incorrect - `id()` is not a function

ashleyfrieze opened this issue · 1 comments

When changing a field's ID, the output migration file uses id as the function to call, when I believe it's newId

Produced:

  myField.editField("headerContent").id("headerContentFoo");

should be

  myField.editField("headerContent").newId("headerContentFoo");

Hi Ashley! Thank you for this report. When we've seen this issue previously (#2), we had discussed "deleting" the old field and "creating" a new field in it's place, rather than changing the ID. This is because the new field may be a completely different field that just happens to align with the old field in the diff.

To put it another way, If the diff produces a ~ on a field, and the id or type of the field has changed, then we should write a delete followed by a create instead of writing an editField.

One thing to consider is whether that would require multiple migrations - we'd need to test this! I vaguely remember that Contentful requires the field to be marked as "not included in response" and to save that first before you can delete it.

Would you be willing to take a stab at writing this? It should be fairly easy inside the "modify.ts" field. Of course you'd need to add a couple test cases in the specs, and then test it against your own Contentful environment as well.