Skip to content
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

feat: add has_send_component to flows table #4113

Merged
merged 9 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,13 @@
permission:
check: {}
columns:
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
- created_at
- flow_id
- data
- role: demoUser
permission:
check:
Expand All @@ -1518,23 +1519,25 @@
id:
_eq: 32
columns:
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
- created_at
- flow_id
- data
comment: A demoUser can only insert a published flow for their own flows and for flows inside the Demo team [id = 32]
- role: platformAdmin
permission:
check: {}
columns:
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
- created_at
- flow_id
- data
- role: teamEditor
permission:
check:
Expand All @@ -1547,22 +1550,24 @@
- role:
_eq: teamEditor
columns:
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
- created_at
- flow_id
- data
select_permissions:
- role: api
permission:
columns:
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
- created_at
- flow_id
- data
filter: {}
allow_aggregations: true
- role: demoUser
Expand All @@ -1571,6 +1576,7 @@
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
Expand All @@ -1582,6 +1588,7 @@
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
Expand All @@ -1593,6 +1600,7 @@
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
Expand All @@ -1604,6 +1612,7 @@
- created_at
- data
- flow_id
- has_send_component
- id
- publisher_id
- summary
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ALTER TABLE "public"."published_flows" DROP COLUMN "has_send_component";

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
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
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 "has_send_component" boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default false hopefully ensures it's false always and I don't need to populate everything

Copy link
Member

@jessicamcinchak jessicamcinchak Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't mean this to sound harsh, but I find comments like this quite confusing to review - are you confident that default 'false' works as you expect it to (based on your local env and how pizza built) or are you asking an implementation question that you'd like a second opinion on?

"Hopefully ensures" sounds like you're not confident in what you've done here and also have not double-checked the pizza's published_flows table to confirm, which is not the right attitude for database migrations !!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah not harsh at all! I was planning to come back with confirmation that it was all good, apologies for the nature of the changes / issues on this one. Thanks for giving feedback even when you think it's harsh, always really appreciate it

default 'false';

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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$;
3 changes: 1 addition & 2 deletions scripts/seed-database/write/flows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ CREATE TEMPORARY TABLE sync_flows (
name text,
templated_from uuid,
description text
);

);
\copy sync_flows FROM '/tmp/flows.csv' WITH (FORMAT csv, DELIMITER ';');

INSERT INTO flows (
Expand Down
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
);
);

\copy sync_published_flows (id, data, flow_id, summary, publisher_id, created_at) FROM '/tmp/published_flows.csv' (FORMAT csv, DELIMITER ';');
RODO94 marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -17,7 +17,7 @@ INSERT INTO published_flows (
summary,
publisher_id,
created_at
)
)
SELECT
id,
data,
Expand All @@ -32,4 +32,4 @@ SET
flow_id = EXCLUDED.flow_id,
summary = EXCLUDED.summary,
publisher_id = EXCLUDED.publisher_id,
created_at = EXCLUDED.created_at;
created_at = EXCLUDED.created_at;
Loading