contentful-cli icon indicating copy to clipboard operation
contentful-cli copied to clipboard

Data migration is not performed within transaction

Open abramenal opened this issue 5 years ago • 0 comments

Expected Behavior

In order to keep data consistency and integrity contentful space migration should implement transactions. It means that any error faced during migration should lead to full rollback of that migration batch.

Actual Behavior

When running migration I see Error: Batch failed in console and some static logs file, but the data In Contentful is modified.

Possible Solution

One of possible ways of solving that is to perform validation round:

  • before it starts changing anything, so validity is becoming a prerequisite
  • after changing all records

By these 2 factors we can assume data integrity and consistency is still there.

Steps to Reproduce

  1. contentful space migration --space-id=<space-id> <filename>.js

Context

I have a model with 2 required fields and 50 entities under it. 1 of that 50 is initially invalid, that means there's a required field that is empty.

So I assume what actually happens is – it rolls out migration for each affected record independently

  • change a record and make it CHANGED
  • try to PUBLISH the changes for a record

PS This single entity is invalid because of the following steps:

  • create field that references Asset (e.g. image)
  • introduce validation rule that enforces this field be not null
  • at some point of time, remove that referenced Asset

Now you have initially invalid entity I'm referring to.

Environment

abramenal avatar Dec 03 '20 11:12 abramenal