Skip to main content

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')

This page was last reviewed on 14 November 2023. It needs to be reviewed again on 14 November 2024 by the page owner #interventions-dev .
This page was set to be reviewed before 14 November 2024 by the page owner #interventions-dev. This might mean the content is out of date.