strapi / codemods

A set of scripts to help migrate Strapi plugins (and in some cases Strapi applications) from v3 to v4
44 stars 13 forks source link

Component field relations dissappearing during the migration process #44

Closed peksi closed 1 year ago

peksi commented 2 years ago

Bug report

Hello and thanks for the hard work with the migration scripts! This is my first PR so let me know in case there is something unclear. Also steps 5. and 8. are something that could raise another issue, but I think that the most critical and valuable thing to solve is the described issue.

Required System information

Describe the bug

Component field relations are dissappearing during the migration process

Steps to reproduce the behavior

  1. npx create-strapi-app@3.5.1 reproductible-relation-error
  2. Create following things in the admin panel:
  1. Add some carpenters with toolboxes that contain tools
  2. Do migration to strapi v4
  3. Remove fields from strapi_permission in the DB
  4. Run the v3-sql-v4-sql migration script
  5. Encounter Cannot read property 'fields' of null error
  6. On table admin_permissions change the null fields to {} in the column properties
  7. Everything runs nicely
  8. Witness that the component relations have disappeared from v4 DB

Expected behavior

Component relations should migrate to v4

Screenshots

To visualize the collections:

Screenshot 2022-09-16 at 15 58 28

Screenshot 2022-09-16 at 15 58 23

V3 API returns:

Screenshot 2022-09-16 at 15 57 48

V4 API returns:

image

V3 database structure seems to show the components_element_stores__tools

Screenshot 2022-09-16 at 16 44 25

but the V4 seems to have discarded it

image

Code snippets

-

Additional context

I'm happy to provide the v3 and v4 databases if needed

MotaZor94 commented 2 years ago

Having the same issue here!

MotaZor94 commented 2 years ago

Quick fix for this:

I think the actual issue here is not related to migration-scripts but the Codemods. That table should be generated first time you run strapi develop in V4 - with the rest of the schema, and it seems like that's not the case.

My guess here is migration script simply doesn't find the corresponding table and it skips the migration of data. Maybe @derrickmehaffy will know more about this.

derrickmehaffy commented 1 year ago

I can confirm this issue, the problem is codemods related.

What I did to reproduce:

image

derrickmehaffy commented 1 year ago

I've created a PR for this which should properly migrate components with relations in them. Could you all test to see if that's the case (you'll still need to run the data migration scripts to get the data moved over properly though)