support delta update to location key

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-11-24 15:57:58 +01:00
parent 54916f2446
commit 3ab57c624a
3 changed files with 14 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Support changing location keys on existing entities, in delta mutations
@@ -943,7 +943,7 @@ describe('DefaultProviderDatabase', () => {
entity_ref: stringifyEntityRef(entity6),
unprocessed_entity: JSON.stringify(entity6),
unprocessed_hash: generateStableHash(entity6),
location_key: 'old', // TODO(freben): This should have been updated to "new", but we do not support that yet
location_key: 'new', // managed to update only the location key
},
]);
},
@@ -237,11 +237,16 @@ export class DefaultProviderDatabase implements ProviderDatabase {
const newHash = generateStableHash(deferred.entity);
const oldState = oldStates.get(entityRef);
if (oldState === undefined) {
// Add any entity that does not exist in the database
toAdd.push({ deferred, hash: newHash });
} else if (
newHash !== oldState.unprocessed_hash ||
(deferred.locationKey ?? null) !== (oldState.location_key ?? null) // normalize undefined/null
(deferred.locationKey ?? null) !== (oldState.location_key ?? null)
) {
// Remove and then re-add any entity that exists, but with a different location key
toRemove.push(entityRef);
toAdd.push({ deferred, hash: newHash });
} else if (newHash !== oldState.unprocessed_hash) {
// Entities with modifications should be pushed through too
toUpsert.push({ deferred, hash: newHash });
}
});
@@ -294,7 +299,7 @@ export class DefaultProviderDatabase implements ProviderDatabase {
// Add any entity that does not exist in the database
toAdd.push(upsertItem);
} else if (
(oldRef?.locationKey ?? undefined) !==
(oldRef.locationKey ?? undefined) !==
(item.deferred.locationKey ?? undefined)
) {
// Remove and then re-add any entity that exists, but with a different location key