-
Notifications
You must be signed in to change notification settings - Fork 283
fix(api): cancel builds on template delete #2377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ed46aeb
81fa346
0f5901b
2ac34a8
4a87453
c3fbe3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,28 @@ | ||
| -- name: DeleteTemplate :many | ||
| -- Deletes a template and returns its alias cache keys for cache invalidation. | ||
| -- Alias keys are captured via CTE before the cascade delete removes them. | ||
| -- Deletes a template and returns alias cache keys and active builds. | ||
| -- Both are captured via CTEs before the cascade delete removes them. | ||
| -- Active builds are returned so the caller can stop them on the orchestrator. | ||
| WITH alias_keys AS ( | ||
| SELECT CASE | ||
| WHEN namespace IS NOT NULL THEN namespace || '/' || alias | ||
| ELSE alias | ||
| END::text AS alias_key | ||
| FROM public.env_aliases | ||
| WHERE env_id = @template_id | ||
| FROM public.env_aliases ea | ||
| WHERE ea.env_id = @template_id | ||
| ), active_builds AS ( | ||
| SELECT atb.build_id, e.cluster_id, b.cluster_node_id | ||
| FROM public.active_template_builds atb | ||
| JOIN public.env_builds b ON b.id = atb.build_id | ||
| JOIN public.envs e ON e.id = atb.template_id | ||
| WHERE atb.template_id = @template_id | ||
| ), deleted AS ( | ||
| DELETE FROM "public"."envs" | ||
| WHERE id = @template_id | ||
| AND team_id = @team_id | ||
| RETURNING id | ||
| DELETE FROM "public"."envs" envs_del | ||
| WHERE envs_del.id = @template_id | ||
| AND envs_del.team_id = @team_id | ||
| RETURNING envs_del.id | ||
| ) | ||
| SELECT alias_key FROM alias_keys | ||
| WHERE EXISTS (SELECT 1 FROM deleted); | ||
| SELECT alias_key, NULL::uuid AS build_id, NULL::uuid AS cluster_id, NULL::text AS cluster_node_id | ||
| FROM alias_keys WHERE EXISTS (SELECT 1 FROM deleted) | ||
| UNION ALL | ||
| SELECT ''::text AS alias_key, build_id, cluster_id, cluster_node_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the alias_key here not implemented?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's hack-y solution as we have two distinct lists returned from 1 query |
||
| FROM active_builds WHERE EXISTS (SELECT 1 FROM deleted); | ||
Uh oh!
There was an error while loading. Please reload this page.