Skip to content

Commit

Permalink
feat: add is_statutory_application_type to published_flows table (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 authored Jan 24, 2025
1 parent cfdd2bf commit 1e5c32a
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 3 deletions.
9 changes: 9 additions & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
- role: demoUser
Expand All @@ -1524,6 +1525,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
comment: A demoUser can only insert a published flow for their own flows and for flows inside the Demo team [id = 32]
Expand All @@ -1536,6 +1538,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
- role: teamEditor
Expand All @@ -1555,6 +1558,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
select_permissions:
Expand All @@ -1566,6 +1570,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
filter: {}
Expand All @@ -1578,6 +1583,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
filter: {}
Expand All @@ -1590,6 +1596,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
filter: {}
Expand All @@ -1602,6 +1609,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
filter: {}
Expand All @@ -1614,6 +1622,7 @@
- flow_id
- has_send_component
- id
- is_statutory_application_type
- publisher_id
- summary
filter: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

alter table "public"."published_flows" drop column "is_statutory_application_type";

CREATE OR REPLACE FUNCTION public.diff_latest_published_flow(source_flow_id uuid, since timestamp with time zone)
RETURNS published_flows
LANGUAGE sql
STABLE
AS $function$
WITH current_published_flow as (
SELECT
id, data, created_at, flow_id, publisher_id, summary, has_send_component
FROM
published_flows
WHERE
published_flows.flow_id = source_flow_id
ORDER BY
created_at desc
LIMIT
1
),
previous_published_flow as (
SELECT
flow_id, data
FROM
published_flows
WHERE
published_flows.flow_id = source_flow_id
AND
published_flows.created_at < since
ORDER BY
created_at desc -- the latest published version before "since"
LIMIT
1
),
data_diff as (
SELECT
flow_id,
( SELECT
jsonb_object_agg(COALESCE(old.key, new.key), new.value)
FROM
jsonb_each(previous_published_flow.data) AS old
FULL OUTER JOIN
jsonb_each(current_published_flow.data) AS new
ON
new.key = old.key
WHERE
new.value IS DISTINCT FROM old.value
) as data -- shallow diff where deleted keys have a 'null' value
FROM
current_published_flow
JOIN
previous_published_flow USING (flow_id)
)
SELECT
id, data_diff.data as data, created_at, flow_id, publisher_id, 'auto generated diff' as summary, has_send_component
FROM
current_published_flow
FULL OUTER JOIN
data_diff USING (flow_id);
$function$
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
alter table "public"."published_flows" add column "is_statutory_application_type" boolean default 'false';
comment on column "public"."published_flows"."is_statutory_application_type" is E'This is updated on publish based on the flow graph containing application.type types that are in the ODP Schema';

CREATE OR REPLACE FUNCTION public.diff_latest_published_flow(source_flow_id uuid, since timestamp with time zone)
RETURNS published_flows
LANGUAGE sql
STABLE
AS $function$
WITH current_published_flow as (
SELECT
id, data, created_at, flow_id, publisher_id, summary, has_send_component, is_statutory_application_type
FROM
published_flows
WHERE
published_flows.flow_id = source_flow_id
ORDER BY
created_at desc
LIMIT
1
),
previous_published_flow as (
SELECT
flow_id, data
FROM
published_flows
WHERE
published_flows.flow_id = source_flow_id
AND
published_flows.created_at < since
ORDER BY
created_at desc -- the latest published version before "since"
LIMIT
1
),
data_diff as (
SELECT
flow_id,
( SELECT
jsonb_object_agg(COALESCE(old.key, new.key), new.value)
FROM
jsonb_each(previous_published_flow.data) AS old
FULL OUTER JOIN
jsonb_each(current_published_flow.data) AS new
ON
new.key = old.key
WHERE
new.value IS DISTINCT FROM old.value
) as data -- shallow diff where deleted keys have a 'null' value
FROM
current_published_flow
JOIN
previous_published_flow USING (flow_id)
)
SELECT
id, data_diff.data as data, created_at, flow_id, publisher_id, 'auto generated diff' as summary, has_send_component, is_statutory_application_type
FROM
current_published_flow
FULL OUTER JOIN
data_diff USING (flow_id);
$function$;
6 changes: 3 additions & 3 deletions scripts/seed-database/write/published_flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TEMPORARY TABLE sync_published_flows (
summary text,
publisher_id int,
created_at timestamptz,
has_send_component boolean
has_send_component boolean
);

/* Ensure columns here are kept in sync with container.sh */
Expand All @@ -19,7 +19,7 @@ INSERT INTO published_flows (
summary,
publisher_id,
created_at,
has_send_component
has_send_component
)
SELECT
id,
Expand All @@ -29,7 +29,7 @@ SELECT
publisher_id,
created_at,
has_send_component
FROM sync_published_flows
FROM sync_published_flows
ON CONFLICT (id) DO UPDATE
SET
data = EXCLUDED.data,
Expand Down

0 comments on commit 1e5c32a

Please sign in to comment.