-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(data): soft-delete imported projects (#1452)
Signed-off-by: Miguel Martinez <[email protected]>
- Loading branch information
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/controlplane/pkg/data/ent/migrate/migrations/20241029113317.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,17 @@ | ||
-- In a previous migration we created projects for already deleted workflows | ||
-- This code makes sure to soft-delete these invalid projects | ||
-- Update projects.deleted_at where all associated workflows are deleted | ||
UPDATE projects p | ||
SET deleted_at = ( | ||
SELECT MIN(w.deleted_at) | ||
FROM workflows w | ||
WHERE w.project_id = p.id | ||
) | ||
WHERE EXISTS ( | ||
SELECT 1 | ||
FROM workflows w | ||
WHERE w.project_id = p.id | ||
GROUP BY w.project_id | ||
HAVING COUNT(*) = COUNT(w.deleted_at) | ||
) | ||
AND p.deleted_at IS NULL; |
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