Skip to content

Commit

Permalink
fix(data): soft-delete imported projects (#1452)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Martinez <[email protected]>
  • Loading branch information
migmartri authored Oct 29, 2024
1 parent 02ed0e0 commit ab6df5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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;
3 changes: 2 additions & 1 deletion app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:Q4CQ7DpD1UL5HhSF2Zdj0ToZe3B9x2zYDvDszaHAzEs=
h1:rVCx+vgsLP6ZUnPUMyNxpIiU1vQ26X9iHeREK/CVFaU=
20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M=
20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g=
20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI=
Expand Down Expand Up @@ -54,3 +54,4 @@ h1:Q4CQ7DpD1UL5HhSF2Zdj0ToZe3B9x2zYDvDszaHAzEs=
20241025074349.sql h1:7jGmBWBb46o7zcInStdDqZM7AiBa/zSnJ2hgmzQYD24=
20241025223253.sql h1:XPtVWq3cLrBC+0u81dVNW/r5KIItARVljKdvdcHIt/w=
20241025224306.sql h1:oBgRGg64ZIyv4eOoHLRE6ceqrjIf6y4dUaM+qvt2RAU=
20241029113317.sql h1:6cl0ZSB3cxou9OzatS/pj+eJkL+dgCJGCfVk+5v/KI0=

0 comments on commit ab6df5c

Please sign in to comment.