-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb4e6ba
initial migration
RODO94 a22751c
add column and populate existing records
RODO94 b905bcf
revert flows table change and populate script
RODO94 888149f
revert flows.sql change
RODO94 00fe27f
remove null from sql script
RODO94 1664928
add has_send_component on seed script
RODO94 d268df1
update permissions and diff_published_flow fn
RODO94 54d9435
remove has_send_component from sync script/seed
RODO94 be39baa
revert script changes
RODO94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
hasura.planx.uk/migrations/1736253268324_add_has_data_to_flows/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$ |
60 changes: 60 additions & 0 deletions
60
hasura.planx.uk/migrations/1736253268324_add_has_data_to_flows/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
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. 👍 |
||
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$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 everythingThere was a problem hiding this comment.
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 !!There was a problem hiding this comment.
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