Migration Question

I'm not sure if it's just the patchwork of documentation that has me confused or if system version migrations aren't as smooth as I would have expected. I'm trying to figure out what the "proper FoundryVTT" way to migrate is and then persist those changes to the database so they don't happen again.

For simplicity:
* I have 2 system versions verA and verB. A user is migrating from verA to verB
* In verA, Item has a schema field (using defineSchema) that is renamed/modified in verB. Really it's about the field from verA needs to be deleted from the database as it no longer serves a purpose.

Using Item.migrateData I can look at the source argument and rename the field. I can just play with source directly or I can use things like Item._addDataFieldMigration and foundry.utils.deleteProperty. However, this only modifies the in-memory copy so that when I reload, this same migration via Item.migrateData has to be done again for each instance.

Is there a slick way of ensuring that this migration I've done for thousands of items via Item.migrateData is done automatically or do I need to do it manually (e.g. track somewhere (flags?) that things were changed for this object and explicitly push it out to the database as the new "correct copy" of this instance of the Item at some point in the future like the ready hook)?

If I need to push out a "correct/updated copy" of the data, what's the correct way to make sure the old field from verA is gone? Item.update({"system": item.system}, {diff: false})? Am I correct in assuming that {diff: false} is the "overwrite everything else that's in here so that the old field from verA is nuked" option?

Thanks in advance
Was this page helpful?