-
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
releases/2.42/migration-notes.md
Outdated
|
||
|
||
##### 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 |
releases/2.42/migration-notes.md
Outdated
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)) |
releases/2.42/migration-notes.md
Outdated
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 |
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.
fixed
releases/2.42/migration-notes.md
Outdated
WHERE trackedentityid IN (SELECT trackedentityid FROM te); | ||
|
||
WITH deleted AS (DELETE FROM trackedentity WHERE trackedentitytypeid IS NULL RETURNING *) SELECT COUNT(*) INTO deleted_count FROM deleted; |
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 should delete only the invalid tracked entities. Without the NOT EXISTS clause, also the fixable ones are going to be deleted
WITH deleted AS (DELETE FROM trackedentity WHERE trackedentitytypeid IS NULL RETURNING *) SELECT COUNT(*) INTO deleted_count FROM deleted; | |
WITH deleted AS (DELETE FROM trackedentity WHERE 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 | |
) | |
RETURNING *) SELECT COUNT(*) INTO deleted_count FROM deleted; |
No description provided.