migration-tool
migration-tool copied to clipboard
Migration Fails on "Migrating Relations"
While migrating from V8 to V9 I encounter the following error while "migrating relations"
Cannot read propery 'map' of undefined
I have tried specifying the order in which to load collections to make sure a collection is only loaded after tables used by its foreignkey constraints already exist, but no luck.
The issue seems to be that the filter at tasks/relations.js:39 has no matches:
const relationsV9 = context.relationsV8
.filter((relation) => {
return (
(relation.collection_many.startsWith("directus_") &&
relation.collection_one.startsWith("directus_")) === false
);
})
I can see in state/relationsV8.json that this is the case, there are no relations meeting that condition.
@moekify What's the meaning of that condition, why are we filtering down to a relation that has ~~collection_one
~~ collection_many
starting with "directus_" but a collection_one
that does not? What would happen to if I had a many-to-one defined between two collections that I invented, wouldn't that collection be excluded from this filter?
Thank you so much for your time on this! Happy to contribute if this turns out to be a bug, but grateful for any clarification that can help me get migrated.
The error "Can't read .map from undefined" definitely makes it sound like a bug!
It must be this one that fails I think 🤔
https://github.com/directus-community/migration-tool/blob/2fdae2ed151f2528755433305db67f5387c88fa7/tasks/relations.js#L58-L59
It may be related to #70 because I also see an error that a many-to-one field has not been configured correctly when I try to create a new Subcategory (has a field "category" which is MTO relation to the Category collection):
I
Hi @lazarporter, I wrote these adjustments to the script months ago, not really in the context anymore. From what I recall, the migration script was definitely a little brittle. I'd suggest you start debugging the script with a test instance that you can run the migration several times one, works well with docker as it is easy to wipe the DB and set it up again using the same credentials.
I don't think I can help you here, as I decommissioned my V8 instance now and just have it backed up somewhere in the corner of my backup solution.
I can try to help you, but this month I'm traveling and quite short on time.
Regarding
const relationsV9 = context.relationsV8
.filter((relation) => {
return (
(relation.collection_many.startsWith("directus_") &&
relation.collection_one.startsWith("directus_")) === false
);
})
You are misreading that condition. It filters out relations that have either collection_one
or collection_many
start with directus_
as for this variable we only want relations that YOU set up and not ones directus is built with itself.
Besides, since I made my adjustments, I definitely think v9 has evolved and had the one or other change. Unsure if this also potentially affects the script.
@lazarporter regarding #70 - I believed it was due to me using directus_users in my relationships and the type has changed from int to an guid so the matching fails. If someone knows different or how to fix, that would be great.