diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/20241029113317.sql b/app/controlplane/pkg/data/ent/migrate/migrations/20241029113317.sql new file mode 100644 index 000000000..b1ce5c3a7 --- /dev/null +++ b/app/controlplane/pkg/data/ent/migrate/migrations/20241029113317.sql @@ -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; diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum index 50d1c3d47..ce5415d58 100644 --- a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum +++ b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum @@ -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= @@ -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=