From 246b1a6ad0549b1f0bb8dddab5943c1b63a5757c Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Fri, 13 Dec 2024 13:39:43 +0200 Subject: [PATCH] Delete disallowed mobile devices from database --- ...te_disallowed_personal_mobile_pairings.sql | 25 +++++++++++++++++++ service/src/main/resources/migrations.txt | 1 + 2 files changed, 26 insertions(+) create mode 100644 service/src/main/resources/db/migration/V477__delete_disallowed_personal_mobile_pairings.sql diff --git a/service/src/main/resources/db/migration/V477__delete_disallowed_personal_mobile_pairings.sql b/service/src/main/resources/db/migration/V477__delete_disallowed_personal_mobile_pairings.sql new file mode 100644 index 0000000000..4610756312 --- /dev/null +++ b/service/src/main/resources/db/migration/V477__delete_disallowed_personal_mobile_pairings.sql @@ -0,0 +1,25 @@ +WITH disallowed_devices AS ( + SELECT id + FROM mobile_device + WHERE + employee_id IS NOT NULL AND + NOT EXISTS ( + SELECT FROM daycare_acl a + JOIN daycare d ON d.id = a.daycare_id + WHERE + d.provider_type = 'MUNICIPAL' AND + a.employee_id = mobile_device.employee_id AND + a.role = 'UNIT_SUPERVISOR' + ) +), push_subscriptions AS ( + DELETE FROM mobile_device_push_subscription + WHERE device IN (SELECT id FROM disallowed_devices) +), push_groups AS ( + DELETE FROM mobile_device_push_group + WHERE device IN (SELECT id FROM disallowed_devices) +), pairings AS ( + DELETE FROM pairing + WHERE mobile_device_id IN (SELECT id FROM disallowed_devices) +) +DELETE FROM mobile_device +WHERE id IN (SELECT id FROM disallowed_devices); diff --git a/service/src/main/resources/migrations.txt b/service/src/main/resources/migrations.txt index 08e47f4563..967228163c 100644 --- a/service/src/main/resources/migrations.txt +++ b/service/src/main/resources/migrations.txt @@ -472,3 +472,4 @@ V473__person_municipality_of_residence.sql V474__holiday_questionnaire_open_ranges.sql V475__application_modified_metadata.sql V476__finance_metadata_process.sql +V477__delete_disallowed_personal_mobile_pairings.sql