Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Component field relations dissappearing during the migration process #44

Closed
peksi opened this issue Sep 16, 2022 · 4 comments · Fixed by #46
Closed

Component field relations dissappearing during the migration process #44

peksi opened this issue Sep 16, 2022 · 4 comments · Fixed by #46
Assignees
Labels
issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product status: confirmed Confirmed by a Strapi Team member or multiple community members

Comments

@peksi
Copy link

peksi commented Sep 16, 2022

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

  • Node.js version: 14 on v3, 16 on v4
  • NPM version: 7.20.3
  • Source Strapi version: 4.3.8
  • Target Strapi version: 3.5.1
  • Source Database: sqlite
  • Target Database: sqlite
  • Operating system: osx
  • Which script are you running: v3-sql-v4-sql

Describe the bug

Component field relations are dissappearing during the migration process

Steps to reproduce the behavior

  1. npx [email protected] reproductible-relation-error
  2. Create following things in the admin panel:
  • Collection Tools
    • name (string)
  • Component Toolbox with fields
    • tools (relation with tools)
      • one toolbox can have multiple tools
  • Collection Carpenter
    • name (string)
    • Toolbox (repeatable component)
  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
Copy link

Having the same issue here!

@MotaZor94
Copy link

MotaZor94 commented Sep 19, 2022

Quick fix for this:

  • create a brand new relation for the specific component in V4
  • make sure the relation is named just as it was in V3, so if it was 'tools', name it 'tools' again
  • this will generate 'links' table, something like 'components_carpenter_components_tools_links'
  • leave it blank
  • run the migration script again and you will see all the correct relations there

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 derrickmehaffy added issue: bug Issue reporting a bug severity: medium If it breaks the basic use of the product but can be worked around status: pending reproduction Waiting for free time to reproduce the issue, or more information labels Sep 19, 2022
@derrickmehaffy derrickmehaffy self-assigned this Sep 30, 2022
@derrickmehaffy derrickmehaffy transferred this issue from strapi/migration-scripts Sep 30, 2022
@derrickmehaffy derrickmehaffy added severity: high If it breaks the basic use of the product status: confirmed Confirmed by a Strapi Team member or multiple community members and removed severity: medium If it breaks the basic use of the product but can be worked around status: pending reproduction Waiting for free time to reproduce the issue, or more information labels Oct 17, 2022
@derrickmehaffy derrickmehaffy moved this from To be reviewed to Reviewed in v3 to v4 Migration Project Oct 17, 2022
@derrickmehaffy
Copy link
Member

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

What I did to reproduce:

  • Created a v3 app and constructed model structure as user defined
  • Manually created v4 app and constructed the same model structure
  • Copied the v3 app to a new folder and ran codemods main branch against it
  • Compared v3 codemods migrated app to manually built v4 app using Meld:

image

@derrickmehaffy
Copy link
Member

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)

Repository owner moved this from Reviewed to Fixed/Shipped in v3 to v4 Migration Project Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue: bug Issue reporting a bug severity: high If it breaks the basic use of the product status: confirmed Confirmed by a Strapi Team member or multiple community members
Projects
Status: Fixed/Shipped
Development

Successfully merging a pull request may close this issue.

3 participants