fix: preserve seeded location identities
This commit is contained in:
@@ -12,52 +12,71 @@ export async function seedVisibleVerticalSlice(
|
||||
const connectionRepository = dataSource.getRepository(LocationConnection);
|
||||
const characterRepository = dataSource.getRepository(Character);
|
||||
|
||||
await locationRepository.upsert(
|
||||
[
|
||||
{
|
||||
id: SOUTH_GATE_ID,
|
||||
key: 'south-gate',
|
||||
name: 'Südtor von Graufurt',
|
||||
description:
|
||||
'Am schwarzen Südtor endet der Schutz Graufurts. Hinter den Wachtfeuern beginnt die stille Weite der Aschenfelder.',
|
||||
regionKey: 'ashen-fields',
|
||||
minRecommendedLevel: 1,
|
||||
maxRecommendedLevel: 1,
|
||||
dangerLevel: 0,
|
||||
isSafe: true,
|
||||
huntingEnabled: false,
|
||||
artworkPath: '/assets/locations/south-gate.webp',
|
||||
},
|
||||
{
|
||||
id: BURNED_ROAD_ID,
|
||||
key: 'burned-road',
|
||||
name: 'Verbrannte Straße',
|
||||
description:
|
||||
'Die alte Handelsstraße führt durch verkohlte Felder. Zwischen Asche und zerbrochenen Wagen warten die ersten Gefahren.',
|
||||
regionKey: 'ashen-fields',
|
||||
minRecommendedLevel: 1,
|
||||
maxRecommendedLevel: 2,
|
||||
dangerLevel: 1,
|
||||
isSafe: false,
|
||||
huntingEnabled: true,
|
||||
artworkPath: '/assets/locations/burned-road.webp',
|
||||
},
|
||||
],
|
||||
['key'],
|
||||
);
|
||||
const locations = [
|
||||
{
|
||||
id: SOUTH_GATE_ID,
|
||||
key: 'south-gate',
|
||||
name: 'Südtor von Graufurt',
|
||||
description:
|
||||
'Am schwarzen Südtor endet der Schutz Graufurts. Hinter den Wachtfeuern beginnt die stille Weite der Aschenfelder.',
|
||||
regionKey: 'ashen-fields',
|
||||
minRecommendedLevel: 1,
|
||||
maxRecommendedLevel: 1,
|
||||
dangerLevel: 0,
|
||||
isSafe: true,
|
||||
huntingEnabled: false,
|
||||
artworkPath: '/assets/locations/south-gate.webp',
|
||||
},
|
||||
{
|
||||
id: BURNED_ROAD_ID,
|
||||
key: 'burned-road',
|
||||
name: 'Verbrannte Straße',
|
||||
description:
|
||||
'Die alte Handelsstraße führt durch verkohlte Felder. Zwischen Asche und zerbrochenen Wagen warten die ersten Gefahren.',
|
||||
regionKey: 'ashen-fields',
|
||||
minRecommendedLevel: 1,
|
||||
maxRecommendedLevel: 2,
|
||||
dangerLevel: 1,
|
||||
isSafe: false,
|
||||
huntingEnabled: true,
|
||||
artworkPath: '/assets/locations/burned-road.webp',
|
||||
},
|
||||
];
|
||||
let southGateId = SOUTH_GATE_ID;
|
||||
let burnedRoadId = BURNED_ROAD_ID;
|
||||
|
||||
for (const location of locations) {
|
||||
const existing = await locationRepository.findOneBy({
|
||||
key: location.key,
|
||||
});
|
||||
const { id, key, ...definition } = location;
|
||||
const persistedId = existing?.id ?? id;
|
||||
|
||||
if (existing) {
|
||||
await locationRepository.update(existing.id, definition);
|
||||
} else {
|
||||
await locationRepository.insert(location);
|
||||
}
|
||||
|
||||
if (key === 'south-gate') {
|
||||
southGateId = persistedId;
|
||||
} else {
|
||||
burnedRoadId = persistedId;
|
||||
}
|
||||
}
|
||||
|
||||
await connectionRepository.upsert(
|
||||
[
|
||||
{
|
||||
fromLocationId: SOUTH_GATE_ID,
|
||||
toLocationId: BURNED_ROAD_ID,
|
||||
fromLocationId: southGateId,
|
||||
toLocationId: burnedRoadId,
|
||||
travelDurationSeconds: 10,
|
||||
ambushChance: '0.0500',
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
fromLocationId: BURNED_ROAD_ID,
|
||||
toLocationId: SOUTH_GATE_ID,
|
||||
fromLocationId: burnedRoadId,
|
||||
toLocationId: southGateId,
|
||||
travelDurationSeconds: 10,
|
||||
ambushChance: '0.0500',
|
||||
enabled: true,
|
||||
|
||||
Reference in New Issue
Block a user