-
Notifications
You must be signed in to change notification settings - Fork 45
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
docs: Implement cascading deletion for obsolete TrackedEntities[DHIS2-15066] #196
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Enrico Colasante <[email protected]>
##### For 2.41 Instances: | ||
|
||
```sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we shouldn't show entities that we can fix in the migration, so we should filter out any tracked entity that has an enrollment with a program that has a defined trackedEntityType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should change this query to not show the entities that will be fixed by the migration
##### For <= 2.40 Instances: | ||
|
||
```sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
releases/2.42/migration-notes.md
Outdated
|
||
|
||
##### Deleting invalid trackedenetities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
##### Deleting invalid trackedenetities | |
##### Deleting invalid tracked entities |
##### For 2.41 Instances: | ||
|
||
```sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should change this query to not show the entities that will be fixed by the migration
|
||
|
||
##### Deleting invalid tracked enetities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
##### Deleting invalid tracked enetities | |
##### Deleting invalid tracked entities |
Starting from version v42, NULL values are no longer allowed in the trackedentitytypeid column. The migration attempted to address the invalid data, but it was unsuccessful. There are two options going forward. | ||
- Change the `NULL` value to a valid trackedentitytypeid. ([Assign trackedentitytyeid to tracked entity](#assign-tracked-entity-type)) | ||
- Completely remove invalid trackedentity record. ([Delete trackedentities](#deleting-invalid-trackedenetities)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Completely remove invalid trackedentity record. ([Delete trackedentities](#deleting-invalid-trackedenetities)) | |
- Completely remove invalid trackedentity record. ([Delete trackedentities](#deleting-invalid-tracked-entities)) |
FROM trackedentity te | ||
WHERE te.trackedentitytypeid IS NULL | ||
AND NOT EXISTS ( | ||
SELECT 1 | ||
FROM enrollment e | ||
WHERE e.trackedentityid = te.trackedentityid | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT COUNT(1) | |
FROM trackedentity te | |
WHERE te.trackedentitytypeid IS NULL | |
AND NOT EXISTS ( | |
SELECT 1 | |
FROM enrollment e | |
WHERE e.trackedentityid = te.trackedentityid | |
); | |
SELECT COUNT(1) | |
FROM trackedentity te | |
WHERE te.trackedentitytypeid IS NULL | |
AND NOT EXISTS ( | |
SELECT 1 | |
FROM enrollment e JOIN program p on e.programid = p.programid | |
WHERE e.trackedentityid = te.trackedentityid and p.trackedentitytypeid IS NOT NULL | |
); |
FROM trackedentityinstance te | ||
WHERE te.trackedentitytypeid IS NULL | ||
AND NOT EXISTS ( | ||
SELECT 1 | ||
FROM programinstance pi | ||
WHERE pi.trackedentityinstanceid = te.trackedentityinstanceid | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT COUNT(1) | |
FROM trackedentityinstance te | |
WHERE te.trackedentitytypeid IS NULL | |
AND NOT EXISTS ( | |
SELECT 1 | |
FROM programinstance pi | |
WHERE pi.trackedentityinstanceid = te.trackedentityinstanceid | |
); | |
SELECT COUNT(1) | |
FROM trackedentityinstance te | |
WHERE te.trackedentitytypeid IS NULL | |
AND NOT EXISTS ( | |
SELECT 1 | |
FROM programinstance pi JOIN program p ON pi.programid = p.programid | |
WHERE pi.trackedentityinstanceid = te.trackedentityinstanceid and p.trackedentitytypeid IS NOT NULL | |
); |
|
||
```sql | ||
UPDATE trackedentity SET trackedentitytypeid=( SELECT trackedentitytypeid FROM trackedentitytype WHERE uid='{REFERENCE_UID}') WHERE trackedentitytypeid IS NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query is changing all the trackedEntities with null
tracked entity type at once.
Can we change the count queries to return the tracked entity uids to be fixed instead of just a count?
And then add them here as a parameter, like AND trackedentityid IN ({uids})
?
FROM enrollment | ||
WHERE enrollment.trackedentityid = trackedentity.trackedentityid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT 1 | |
FROM enrollment | |
WHERE enrollment.trackedentityid = trackedentity.trackedentityid | |
SELECT 1 | |
FROM enrollment e JOIN program p on e.programid = p.programid | |
WHERE e.trackedentityid = te.trackedentityid and p.trackedentitytypeid IS NOT NULL |
No description provided.