-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Hotfix] Fixe la multiplication des moyens dans les missions (#931)
## Related Pull Requests & Issues None ---- - [ ] Tests E2E (Cypress)
- Loading branch information
Showing
20 changed files
with
113 additions
and
476 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
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
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
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
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
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
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
40 changes: 40 additions & 0 deletions
40
...s/db/migration/internal/V0.101__reconnect_mission_resources_to_control_unit_resources.sql
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,40 @@ | ||
ALTER TABLE public.missions_control_resources | ||
ADD CONSTRAINT fk_missions_control_resources_control_resource_id_control_unit_resources | ||
FOREIGN KEY (control_resource_id) | ||
REFERENCES public.control_unit_resources(id); | ||
|
||
-- Remove duplicates in `missions_control_resources` (both same `mission_id` and `control_resource_id`): | ||
|
||
WITH missions_with_duplicate_resources AS ( | ||
SELECT | ||
mission_id, | ||
control_resource_id, | ||
ARRAY_AGG(id) AS ids | ||
FROM missions_control_resources | ||
GROUP BY 1, 2 | ||
HAVING COUNT(*) > 1 | ||
), | ||
|
||
missions_with_duplicate_resources_unnested AS ( | ||
SELECT | ||
mission_id, | ||
control_resource_id, | ||
unnest(ids) AS id | ||
FROM missions_with_duplicate_resources | ||
), | ||
|
||
missions_with_duplicate_resources_numbered AS ( | ||
SELECT | ||
*, | ||
ROW_NUMBER() OVER (PARTITION BY mission_id, control_resource_id ORDER BY id) AS rk | ||
FROM missions_with_duplicate_resources_unnested | ||
), | ||
|
||
missions_control_resources_to_delete AS ( | ||
SELECT id | ||
FROM missions_with_duplicate_resources_numbered | ||
WHERE rk > 1 | ||
) | ||
|
||
DELETE FROM missions_control_resources | ||
WHERE id IN (SELECT id FROM missions_control_resources_to_delete) |
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.