Skip to content

Commit

Permalink
control-plane: fix prune_unchanged_draft_specs function
Browse files Browse the repository at this point in the history
The `prune_unchanged_draft_specs` sql function contained a serious bug that
would cause it to always prune _all_ drafts that the user has access to.  This
was due to the function parameter having the same name as a column in the
query, which changed the `where draft_specs.draft_id = draft_id` clause to be
evaluated as if it were `where draft_specs.draft_id = draft_specs.draft_id`.
Changing the parameter name disambiguates this and fixes the bug.
  • Loading branch information
psFried committed Oct 17, 2023
1 parent 714b5a0 commit 46c6053
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions supabase/migrations/35_prune_unchanged_draft_specs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ comment on view unchanged_draft_specs is
current `live_specs`. For collection specs that use schema inference, this will only include
them if the `inferred_schema_md5` matches the `effective_inferred_schema_md5`';

create function prune_unchanged_draft_specs(draft_id flowid)
create function prune_unchanged_draft_specs(prune_draft_id flowid)
returns table(
catalog_name catalog_name,
spec_type catalog_spec_type,
Expand All @@ -116,11 +116,11 @@ returns table(
effective_inferred_schema_md5 text
) as $$
with to_prune as (
select * from unchanged_draft_specs u where u.draft_id = draft_id
select * from unchanged_draft_specs u where u.draft_id = prune_draft_id
),
del as (
delete from draft_specs ds
where ds.draft_id = draft_id
where ds.draft_id = prune_draft_id
and ds.catalog_name in (select catalog_name from to_prune)
)
select
Expand Down

0 comments on commit 46c6053

Please sign in to comment.