Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete entity less aggressively when deleting to reprocess data from BC Registries #802

Open
ianco opened this issue Dec 11, 2024 · 0 comments
Assignees

Comments

@ianco
Copy link
Contributor

ianco commented Dec 11, 2024

Currently when we reprocess data from BC Registries we either:

  • reprocess the company from BC Reg and post and new/updated data
  • delete the company from OrgBook completely, and then reprocess (completely) from the source BC Reg database

The second method - delete and then reprocess - is sometimes necessary to make sure we don't wind up with "bad history" in OrgBook (i.e. something in the source data has changed and we want to replace the data in OrgBook, rather than just appending any new data).

This is a problem if there are credentials from other issuers - the current approach will aggressively delete these along with all other data attached to this company.

Instead, it should delete only credentials issued from BC Registries (Registration, BN and Relationship credentials), and then only if there are not more credentials it should delete the company's topic record.

This will create a short-term issue in OrgBook - a topic record for the company will exist, along with credential(s) from other issuer(s) - however this will be cleaned up once the company is re-processed from BC Registries and the credentials are re-issued.

The script in question is here - https://github.com/bcgov/aries-vcr/tree/main/server/vcr-server/agent_webhooks/management/commands

The script currently executes the following steps:

  1. Delete all credentials for the selected company from the wallet (by selecting all OrgBook credentials, and then deleting each credential from the wallet based on the credential_id)
  2. Delete all "related company" credentials - these are credentials owned by other companies that point to the company we are deleting as a "related company"
  3. Delete the topic from OrgBook - Django does a cascading delete that deletes all information on this topic.

Do update the process to do a "selected delete":

  1. Need to configure the "BC Reg Issuer ID", and only delete credentials that are issued by this issuer. In the OrgBook database, the issuer info is in the issuer table, and BC registries can be identified with name='BC Corporate Registry'. The credentials (to delete) can then be filtered by the Credential.CredentialSet.CredentialType.Issuer attribute. At this point set a flag (non_bc_reg_creds) if there are any credentials for this company that are not issued by BC Registries.
  2. Based on step 1 (non_bc_reg_creds) - if true (ie there are non-BC Reg credentials) then skip this step (since we will leave the company's topic record, any "related company" records will still have a company to point to.
  3. Based on step 1 (non_bc_reg_creds) - if false (i.e. all credentials were issued by BC Reg) then proceed as normal. If true (ie there are non-BC Reg credentials) then a selective delete is required:
    • Select all credentialTypes for the BC Reg issuer, and then delete all hookable_cred records for each credentialType for the selected company
    • Select all CredentialSets (topic.credential_sets) and delete each credentialSet issued by the BC Reg issuer
    • Delete all name and address objects for the selected company (not sure if these will get cascade-deleted when the credentialSet gets deleted)
    • Select all TopicRelationship records owned by the selected company and delete them.

This should leave the company's topic record, along with the CredentialSets and Credentials (and related attributes) for non-BC Reg credentials.

At this point the data will be in an incomplete state, and if viewed through the OrgBook UI most data fields will be blank. The company should be re-processed from BC Reg as soon as possible.

(The effort shouldn't be more than a couple of days, including testing.)

@ianco ianco self-assigned this Dec 11, 2024
@ianco ianco assigned swcurran and unassigned ianco Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants