Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data fix for wrongly deleted document headers (#1048)
https://eaflood.atlassian.net/browse/WATER-4627 We received a report that an external user was unable to link **MD/054/0009/047** to their account (it returned the error "We cannot find these licence numbers"). We reproduced the issue in pre-prod and tracked down the cause. When you add a licence number, the legacy code runs this query to pull it from `CRM.document_headers`. ```sql SELECT "crm"."document_header" .* FROM "crm"."document_header" WHERE "crm"."document_header"."system_external_id" = $1 AND "crm"."document_header"."company_entity_id" IS NULL AND "crm"."document_header"."metadata"->'IsCurrent' != $2 AND "crm"."document_header"."date_deleted" IS NULL AND "crm"."document_header"."metadata"->>'IsCurrent' != $3 ORDER BY "crm"."document_header"."system_external_id" ASC LIMIT $4 -- [ 'MD/054/0009/047', 'false', 'false', 300 ] ``` On 2023-10-03 the [water-abstraction-import](https://github.com/DEFRA/water-abstraction-import) marked the `crm.document_header` record as deleted. This is a step in the import process where it checks for deleted 'document'. ```javascript // src/lib/connectors/import.js const deleteCrmV1DocumentsQuery = ` update crm.document_header set date_deleted = now() where system_external_id not in ( select l."LIC_NO" from import."NALD_ABS_LICENCES" l ) and date_deleted is null and regime_entity_id = '0434dc31-a34e-7158-5775-4694af7a60cf'; ` ``` The knowledge of why the query didn't see this licence in the NALD data on that date is now lost to the universe! However, we can clearly see that the licence has a record in NALD, so it shouldn't have been picked up. We've checked if others are affected, and fortunately, only 5 licences have a populated `date_deleted` though they have a matching record in the NALD data. This change adds a migration data fix to reset the `date_deleted` to `null` for the 5 affected licences.
- Loading branch information