When changing unit_key_fields, the relevant DB units may need to be prepared during migration BEFORE indexes are applied
pulp-manage-db currently creates indexes before migrations are run.
In most cases this is desirable behaviour since it ensures Mongo will enforce uniqueness constraints (see https://pulp.plan.io/issues/4055).
However, when dropping a field from the unit_key_fields of a DB model, this means that the new key is applied (as an index) BEFORE the migration has had a chance to prepare the existing units for the new key.
This can easily turn previously unique units into duplicates, thus breaking any attempt to migrate them.
This makes it essentially impossible to change a unit key in this way.
Add an optional pre index part for DB migrations
This is needed to provide a way to prepare the data base for an index change BEFORE that index is applied. The new mechanism is subject to certain risks and limitations. It should only be used where absolutely necessary.
#1 Updated by quba42 about 1 year ago
The following change (https://github.com/pulp/pulp/pull/3919) is designed to tackle this issue, albeit with some significant limitations and not without introducing some risk.
On the positive side, it does so in a way that should not affect any existing migrations that do not make use of the newly introduced "prepare_reindex_migration" at all.
The hope is that usage of this new function will remain a rare exception. Appropriate warnings and usage instructions will still be added to all doc strings.
Please register to edit this issue