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

fix: Programinstance permanent deletion by first deleting sms entries #19830

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public int deleteSoftDeletedProgramInstances() {
String pmSelect =
"(select id from programmessage where programinstanceid in " + piSelect + " )";

String smsSelect =
"(select outboundsmsid from programinstance_outboundsms where programinstanceid in "
+ piSelect
+ " )";

/*
* Delete event values, event value audits, event comments, events,
* enrollment comments, enrollments
Expand All @@ -200,6 +205,12 @@ public int deleteSoftDeletedProgramInstances() {
+ pmSelect,
"delete from programmessage_phonenumbers where programmessagephonenumberid in "
+ pmSelect,

// delete SMS objects linked to PIs
"delete from outbound_sms_recipients where outbound_sms_id in " + smsSelect,
"delete from programinstance_outboundsms where outboundsmsid in " + smsSelect,
"delete from outbound_sms where id in " + smsSelect,

// delete comments linked to both PIs and PSIs
"delete from programstageinstancecomments where programstageinstanceid in " + psiSelect,
"delete from programinstancecomments where programinstanceid in " + piSelect,
Expand Down Expand Up @@ -266,6 +277,11 @@ public int deleteSoftDeletedTrackedEntityInstances() {
String psiPmSelect =
"(select id from programmessage where programstageinstanceid in " + psiSelect + " )";

String smsSelect =
"(select outboundsmsid from programinstance_outboundsms where programinstanceid in "
+ piSelect
+ " )";

/*
* Delete event values, event audits, event comments, events, enrollment
* comments, enrollments, tei attribtue values, tei attribtue value
Expand All @@ -281,6 +297,12 @@ public int deleteSoftDeletedTrackedEntityInstances() {
+ teiPmSelect,
"delete from programmessage_phonenumbers where programmessagephonenumberid in "
+ teiPmSelect,

// delete SMS objects linked to PIs
"delete from outbound_sms_recipients where outbound_sms_id in " + smsSelect,
"delete from programinstance_outboundsms where outboundsmsid in " + smsSelect,
"delete from outbound_sms where id in " + smsSelect,

// delete objects related to any message related to obsolete PIs
"delete from programmessage_deliverychannels where programmessagedeliverychannelsid in "
+ piPmSelect,
Expand Down
Loading