-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cleanup unarchived application status
Archives lingering rows of the application status table that were not archived as they were created before the auto archiving function was created, leaves behind the two latest application status one for analyst and one for applicant.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- Deploy ccbc:clean_application_status to pg | ||
|
||
BEGIN; | ||
|
||
WITH latest_rows AS ( | ||
SELECT application_id, MAX(created_at) AS latest_created_at | ||
FROM ccbc_public.application_status | ||
WHERE archived_at IS NULL | ||
AND status IN ('applicant_approved', 'applicant_cancelled', 'applicant_closed', 'applicant_complete', 'applicant_conditionally_approved', 'applicant_on_hold', 'applicant_received', 'draft', 'received', 'submitted', 'withdrawn') | ||
GROUP BY application_id | ||
) | ||
UPDATE ccbc_public.application_status AS a | ||
SET archived_at = CURRENT_TIMESTAMP | ||
FROM latest_rows AS l | ||
WHERE a.application_id = l.application_id | ||
AND a.created_at <> l.latest_created_at | ||
AND a.archived_at IS NULL | ||
AND a.status IN ('applicant_approved', 'applicant_cancelled', 'applicant_closed', 'applicant_complete', 'applicant_conditionally_approved', 'applicant_on_hold', 'applicant_received', 'draft', 'received', 'submitted', 'withdrawn'); | ||
|
||
WITH latest_rows AS ( | ||
SELECT application_id, MAX(created_at) AS latest_created_at | ||
FROM ccbc_public.application_status | ||
WHERE archived_at IS NULL | ||
AND status IN ('analyst_withdrawn', 'approved', 'assessment', 'cancelled', 'closed', 'complete', 'conditionally_approved', 'on_hold', 'recommendation', 'screening') | ||
GROUP BY application_id | ||
) | ||
UPDATE ccbc_public.application_status AS a | ||
SET archived_at = CURRENT_TIMESTAMP | ||
FROM latest_rows AS l | ||
WHERE a.application_id = l.application_id | ||
AND a.created_at <> l.latest_created_at | ||
AND a.archived_at IS NULL | ||
AND a.status IN ('analyst_withdrawn', 'approved', 'assessment', 'cancelled', 'closed', 'complete', 'conditionally_approved', 'on_hold', 'recommendation', 'screening'); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Revert ccbc:clean_application_status from pg | ||
|
||
BEGIN; | ||
|
||
-- No real revert due to ccbc_private.archived_records_are_immutable (Deleted records cannot be modified) | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters