sul-dlss / FOLIO-Project-Stanford

Task management for Stanford’s analysis of FOLIO.
2 stars 0 forks source link

As part of Quesnalia upgrade, run script to correct holdings #672

Open dlrueda opened 2 months ago

dlrueda commented 2 months ago

In Poppy, using Bulk Edit to update the holdings location could result in incorrect fields being saved to the holdings json. https://folio-org.atlassian.net/browse/MODBULKOPS-357

For us, we cannot move items to the holdings after the permanentLocation block was mistakenly added to the holdings record.

A script was created to fix these, and is in fact a step in the Quesnelia migration. So we'll run as part of our upgrade to Quesnelia.

To fix one-offs, GET /holdings-storage/holdings/{uuid}, remove the bad block from the json, and PUT /holdings-storage/holdings/{uuid}

dlrueda commented 2 months ago

Script is

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER audit_holdings_record;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER set_holdings_record_md_json_trigger;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER set_holdings_record_md_trigger;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER set_holdings_record_ol_version_trigger;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER set_id_in_jsonb;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER update_holdings_record_references;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER updatecompleteupdateddate_holdings_record_delete;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  DISABLE TRIGGER updatecompleteupdateddate_holdings_record_insert_update;

UPDATE {tenant_name}_mod_inventory_storage.holdings_record
    SET jsonb=jsonb - 'permanentLocation' - 'illPolicy' - 'holdingsItems' - 'bareHoldingsItems' - 'holdingsInstance'
    WHERE jsonb ? 'permanentLocation'
    OR jsonb ? 'illPolicy'
    OR jsonb ? 'holdingsItems'
    OR jsonb ? 'bareHoldingsItems'
    OR jsonb ? 'holdingsInstance';

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER audit_holdings_record;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER set_holdings_record_md_json_trigger;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER set_holdings_record_md_trigger;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER set_holdings_record_ol_version_trigger;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER set_id_in_jsonb;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER update_holdings_record_references;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER updatecompleteupdateddate_holdings_record_delete;

ALTER TABLE {tenant_name}_mod_inventory_storage.holdings_record
  ENABLE TRIGGER updatecompleteupdateddate_holdings_record_insert_update;