Skip to content

Commit

Permalink
control-plane: fix pruning of unchanged specs
Browse files Browse the repository at this point in the history
This is a quick fix for the pruning of unchanged draft specs. It stops
trying to account for inferred schema changes, since those are now part
of the spec itself, and the `inferred_schema_md5` column is no longer
used. (We can remove it in a subsequent migration).
  • Loading branch information
psFried committed Aug 15, 2024
1 parent 9370a19 commit f50987d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
begin;

create or replace view unchanged_draft_specs as
select
draft_id,
catalog_name,
spec_type,
live_spec_md5,
draft_spec_md5,
inferred_schema_md5,
live_inferred_schema_md5
from draft_specs_ext d
where draft_spec_md5 = live_spec_md5;
grant select on unchanged_draft_specs to authenticated;
comment on view unchanged_draft_specs is
'View of `draft_specs_ext` that is filtered to only include specs that are identical to the
current `live_specs`.';

commit;
46 changes: 13 additions & 33 deletions supabase/tests/prune_unchanged_draft_specs.test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ create function tests.test_prune_unchanged_draft_specs()
returns setof text as $$
declare
draft_id flowid;
si_collection_spec json = '{"writeSchema":{},"readSchema": {"$ref":"flow://inferred-schema"},"key":["/id"]}'::json;
reg_collection_spec json = '{"schema":{},"key":["/id"]}'::json;
collection_spec json = '{"schema":{},"key":["/id"]}'::json;
begin

insert into user_grants (user_id, object_role, capability) values
('11111111-1111-1111-1111-111111111111', 'aliceCo/', 'admin');

insert into inferred_schemas (collection_name, schema, flow_document) values
('aliceCo/collA', '{"description": "collA has a schema"}', '{}'),
('aliceCo/collC', '{"description": "collC has a schema"}', '{}'),
('aliceCo/collD', '{"description": "collD has a schema"}', '{}'),
('aliceCo/collE', '{"description": "collE has a schema"}', '{}'),
('aliceCo/collG', '{"description": "collG has a schema"}', '{}');

insert into live_specs (catalog_name, spec_type, spec, inferred_schema_md5) values
Expand Down Expand Up @@ -45,13 +41,8 @@ begin
},
"bindings": []
}', null),
('aliceCo/collA', 'collection', reg_collection_spec, 'different md5 that should be ignored'),
('aliceCo/collB', 'collection', si_collection_spec, null),
('aliceCo/collC', 'collection', si_collection_spec,
(select md5 from inferred_schemas where collection_name = 'aliceCo/collC')),
('aliceCo/collD', 'collection', si_collection_spec, null),
('aliceCo/collE', 'collection', si_collection_spec, 'mock stale md5'),
('aliceCo/collG', 'collection', si_collection_spec,
('aliceCo/collA', 'collection', collection_spec, 'different md5 that should be ignored'),
('aliceCo/collG', 'collection', collection_spec,
(select md5 from inferred_schemas where collection_name = 'aliceCo/collG'));


Expand Down Expand Up @@ -81,35 +72,24 @@ begin
},
"bindings": []
}'),
-- should be pruned because spec is identical. Note that the inferred schema
-- is still setup above so we can assert it is ignored when the spec does not
-- $ref it.
(draft_id, 'aliceCo/collA', 'collection', reg_collection_spec),
-- should prune because spec is idential and inferred schema is still null/missing
(draft_id, 'aliceCo/collB', 'collection', si_collection_spec),
-- should prune because spec is identical and inferred schema md5 is the same
(draft_id, 'aliceCo/collC', 'collection', si_collection_spec),
-- should keep because inferred schema md5 changed from null to some
(draft_id, 'aliceCo/collD', 'collection', si_collection_spec),
-- should keep because inferrred schema md5 changed
(draft_id, 'aliceCo/collE', 'collection', si_collection_spec),
-- should be pruned because spec is identical.
(draft_id, 'aliceCo/collA', 'collection', collection_spec),
-- should keep because it is new
(draft_id, 'aliceCo/collF', 'collection', si_collection_spec),
-- should keep because spec changed (whitespace after "writeSchema" to document that behavior)
(draft_id, 'aliceCo/collF', 'collection', collection_spec),
-- should keep because spec changed (whitespace only change, in order to document that behavior)
(draft_id, 'aliceCo/collG', 'collection', '{
"writeSchema":{},
"readSchema": {"$ref": "flow://inferred-schema"},
"schema":{ },
"key": ["/id"]
}');

return query select set_eq(
$i$ select catalog_name from prune_unchanged_draft_specs('$i$ || draft_id || $i$') $i$,
'{aliceCo/capA, aliceCo/collA, aliceCo/collB, aliceCo/collC}'::text[]
'{aliceCo/capA, aliceCo/collA}'::text[]
);

return query select results_eq(
$i$ select catalog_name::text from draft_specs where draft_id = '$i$ || draft_id || $i$' order by catalog_name $i$,
$i$ values ('aliceCo/capB'),('aliceCo/collD'),('aliceCo/collE'),('aliceCo/collF'),('aliceCo/collG') $i$
$i$ values ('aliceCo/capB'),('aliceCo/collF'),('aliceCo/collG') $i$
);

end;
Expand Down

0 comments on commit f50987d

Please sign in to comment.