Skip to content

Commit

Permalink
moving the delete command to a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
kth13 committed Aug 2, 2024
1 parent 51e799f commit a9f05be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
41 changes: 41 additions & 0 deletions source/runbooks/delete-stale-draft-referrals.html.md.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Production support commands
weight: 54
last_reviewed_on: 2023-11-14
review_in: 1 year
---

# Deleting stale draft referrals


```

### sample command for cascade deleting draft referrals based on a condition

```
delete from referral_service_user_data where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from referral_details where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from draft_oasys_risk_information where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from referral_complexity_level_ids where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from referral_selected_service_category where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from draft_referral where id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')



27 changes: 0 additions & 27 deletions source/runbooks/runbook-commands.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,5 @@ kubectl scale deployment hmpps-interventions-service-performance-report -n hmpps

```

### sample command for cascade deleting draft referrals based on a condition

```
delete from referral_service_user_data where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from referral_details where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from draft_oasys_risk_information where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from referral_complexity_level_ids where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from referral_selected_service_category where referral_id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')

delete from draft_referral where id in (select dr.id from draft_referral dr
left outer join referral r on dr.id = r.id
where r.id is null and dr.created_at <= CURRENT_DATE - INTERVAL '90 days')



0 comments on commit a9f05be

Please sign in to comment.