This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
[Solution found, needs review from Strapi] Multi-word Collection Types with many-to-many Relationships are skipped #87
Labels
issue: bug
Issue reporting a bug
severity: medium
If it breaks the basic use of the product but can be worked around
source: v3-SQL to v4-SQL
status: pending reproduction
Waiting for free time to reproduce the issue, or more information
Bug report
Required System information
v16.17.0
v8.15.0
v3.5.0
v4.5.5
MySQL
MySQL
Windows 10 64-bit
.env
files)Describe the bug (TL;DR Version)
Please see here: https://github.com/strapi/migration-scripts/blob/main/v3-sql-v4-sql/migrate/helpers/relationHelpers.js#L49-L50
ManyToMany relationships in CollectionTypes with hyphens (e.g.
Care-roles
) are not migrated properly (screenshots in the full description below).The following lines need to have the value of
modelF
andattributeF
wrapped insnakeCase()
, like so:Through testing on my side, wrapping just
modelF
seems to work. However, no better / worse behavior was observed when adding it toattribtueF
, so ideally I'd need a second pair of eyes from the Strapi team to check for any consequences when adding it to theattributeF
field.Describe the bug (Full Version)
I have two CollectionTypes that interact with one another,
articles
andcare-roles
. They hold a many-to-many relationship, where manyarticles
can hold manycare-roles
.When I run the migration scripts, I seem to lose all relationships relating to the
care-roles
collection. I would expect to see something like this in the migration script console output, when run:However, no message appears. This means the migration script has skipped over it for some reason. I spent a few hours debugging the migration script in VSCode line-by-line, and found the cause of it.
As shown in this screenshot, this will mean that the migrations script is looking for a table called
articles_care-roles__care-roles_articles
(note the hyphens), which doesn't exist, and so is skipped over.Whilst looking for potential fixes to this, I could see that the one-to-many
addRelation()
function usessnakeCase()
. This sounded like something I needed for my many-to-many relationship. I added it like so and re-ran the script:This seemed to fix the issue and all of my relationships migrated properly upon re-run! I ran this fix twice, once with just the
modelF
value snakecased, and once with bothmodelF
andattributeF
snakecased.There appears to be no difference in behavior; both fixed the issue properly, which makes me wonder if I'm potentially causing any other issues under-the-hood with this.
It would be much appreciated if I could have this reviewed by someone on the Strapi team, as I've found the solution and would like this to be reviewed and a fix merged into the repo, but I've been trying to contact the Strapi team for ~3 weeks to raise this issue, to no avail.
Steps to reproduce the behavior
Expected behavior
The Care-roles relationships should be migrated properly, outputting the following message in the console:
Screenshots
Relevant screenshots included above, please see my messages in the Strapi discord for more screenshots:
Code snippets
Code samples AND pending solution posted above.
Additional context
This is pretty-much solved and I just need this solution reviewed and merged into the main repo by a member of the Strapi team. The only reason I haven't made this a PR is because I'm unsure whether
attributeF
requires the snake-case fix, so I'd like someone from the Strapi team to review the change to ensure no further issues happen with a result.I'll be running this eventually on a real client's database, so having this fix officially merged in would be a real confidence-booster in running the script against their real database in a few weeks time.
The text was updated successfully, but these errors were encountered: