migration-scripts icon indicating copy to clipboard operation
migration-scripts copied to clipboard

Possible Race Condition While Inserting Data

Open kasonde opened this issue 1 year ago • 0 comments

Bug report

Required System information

  • Node.js version: v14
  • NPM version: v6
  • Source Strapi version: 3.6.11
  • Target Strapi version: v4.10.5
  • Source Database: Postgres
  • Target Database: Postgres
  • Which script are you running: Migrate

Describe the bug

While the scripts add data from the source to the destination, users seem to be reaching race conditions seemingly caused by PrimaryKey collisions in some database tables. The currently proposed solution from interaction with the user and observation is to add a setTimeout call between SQL create statements to slow down the process allowing the prior process to complete.

Steps to reproduce the behavior

This occurred during a user's routine migration process. To our knowledge, there aren't any steps outside of what we prescribe in our guides that the users followed.

Additional context

If more context is required, @kasonde or @derrickmehaffy would do their best gather the information required. For now, here's an example of the output they got from the scripts:

error: insert into "strapi_ecomm_<retracted>_v4"."admin_permissions" ("action", "conditions", "created_at", "properties", "subject", "updated_at") values ($1, $2, $3, $4, $5, $6) returning "id" - duplicate key value violates unique constraint "admin_permissions_pkey"
error: insert into "strapi_ecomm_<retracted>_v4"."admin_permissions" ("action", "conditions", "created_at", "properties", "subject", "updated_at") values ($1, $2, $3, $4, $5, $6) returning "id" - duplicate key value violates unique constraint "admin_permissions_pkey"

Anywhere you see <retracted> is information about the user we'd prefer to keep private but has no effect on the process. It is just three letters, i.e strapi_ecomm_abc_v4.

kasonde avatar Jun 13 '23 09:06 kasonde