blastmud/docs/dbfixes.md
Condorra 6bb3e6a335 Implement NPC AI for Ronald
Also add more armour to protect against guns.
2024-06-12 22:40:09 +10:00

2.9 KiB

Diagnostics to run on the database

Dead NPCs with no reclone task (permadead without intervention)

The following should be 0. I've seen it non-zero in test, possibly from old data though.

select count(*) from items i where details->>'item_type' = 'npc' and details->>'death_data' is not null and not exists (select 1 from tasks t where t.details->>'task_type' = 'RecloneNPC' and t.details->>'task_code' = i.details->>'item_code');

Fix with something like:

INSERT INTO tasks (details) SELECT JSONB_BUILD_OBJECT('is_static', false, 'task_type', 'RecloneNPC', 'task_code', details->>'item_code', 'task_details', JSONB_BUILD_OBJECT('npc_code', details->>'item_code'), 'next_scheduled', now(), 'consecutive_failure_count', 0) AS details FROM items i WHERE i.details->>'item_type' = 'npc' AND i.details->>'death_data' IS NOT NULL AND NOT EXISTS (SELECT 1 FROM tasks t WHERE t.details->>'task_type' = 'RecloneNPC' AND t.details->>'task_code' = i.details->>'item_code');

Corpses with no rot handler

select count(*) from items i where details->>'item_type' = 'corpse' and not exists (select 1 from tasks t where t.details->>'task_type' = 'RotCorpse' and t.details->>'task_code' = i.details->>'item_code');

This is expected to be 0 - haven't seen any instances of it deviating, so any bugs seen involving corpses probably aren't due to stale data.

NPC combat non-symmetrical attacking / attacked_by

select i1.details->>'item_code' as i1_code, i1.details->>'active_combat' as i1_combat, i1.details->>'location' as i1_loc, i2.details->>'item_code' as i2_code, i2.details->>'active_combat' as i2_combat, i2.details->>'location' as i2_loc from items i1 join items i2 on i2.details->>'item_type' = (regexp_split_to_array(i1.details->'active_combat'->>'attacking', '/'))[1] and i2.details->>'item_code' = (regexp_split_to_array(i1.details->'active_combat'->>'attacking', '/'))[2] where not exists (select 1 from jsonb_array_elements_text(i2.details->'active_combat'->'attacked_by') e where e = ((i1.details->>'item_type') || '/' || (i1.details->>'item_code')));

This should be empty, but there has been a bug breaking this.

Other types of migrations

Rename a skill

Something like this: with fexdet as (select item_id, jsonb_strip_nulls(jsonb_set(details, '{total_skills,Fuck}', 'null')) as details, details->'total_skills'->'Fuck' as f from items), amenddet as (select jsonb_set(details :: jsonb, '{total_skills,Share}', f :: jsonb) as details, item_id from fexdet where f is not null) update items i set details = a.details from amenddet a where i.item_id = a.item_id;

Advanced admin via the database to help debugging / admin

Immediately reclone a dead NPC

Set task_code to the NPC's ID as appropriate. next_scheduled can be any time in the past. update tasks set details=jsonb_set(details, '{next_scheduled}', '"2024-01-01T00:00:00Z"') where details->>'task_type' = 'RecloneNPC' and details->>'task_code' = 'ronalds_house_ronald';