fix(api): key starting-sword seed idempotency on its real unique index
The CharacterItem idempotency check was looking up by the seed's own literal id instead of the (characterId, itemDefinitionId) unique index that CharacterItem actually enforces. If the demo character had already looted a worn-short-sword naturally, re-running the seed would miss that row and try to insert a colliding duplicate, breaking seeding instead of being a safe no-op. Look up by the real domain key and reuse whatever id is found when wiring up the CharacterEquipment row.
This commit is contained in:
@@ -218,8 +218,11 @@ export async function seedVisibleVerticalSlice(
|
||||
const characterEquipmentRepository = dataSource.getRepository(CharacterEquipment);
|
||||
|
||||
const existingStartingSword = await characterItemRepository.findOneBy({
|
||||
id: DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
characterId: DEMO_CHARACTER_ID,
|
||||
itemDefinitionId: ITEM_IDS['worn-short-sword'],
|
||||
});
|
||||
const startingSwordItemId =
|
||||
existingStartingSword?.id ?? DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID;
|
||||
if (!existingStartingSword) {
|
||||
await characterItemRepository.insert({
|
||||
id: DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
@@ -238,7 +241,7 @@ export async function seedVisibleVerticalSlice(
|
||||
id: DEMO_CHARACTER_STARTING_WEAPON_EQUIPMENT_ID,
|
||||
characterId: DEMO_CHARACTER_ID,
|
||||
slot: EquipmentSlot.WEAPON,
|
||||
characterItemId: DEMO_CHARACTER_STARTING_WEAPON_ITEM_ID,
|
||||
characterItemId: startingSwordItemId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user