From 8d744780cc550e3508aa571120afdfb2927ae090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 17 May 2024 11:30:25 +0100 Subject: [PATCH] chore: Feedback sync script [skip pizza] --- scripts/seed-database/container.sh | 14 ++++- scripts/seed-database/write/feedback.sql | 70 ++++++++++++++++++++++++ scripts/seed-database/write/main.sql | 6 +- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 scripts/seed-database/write/feedback.sql diff --git a/scripts/seed-database/container.sh b/scripts/seed-database/container.sh index c3647b268c..a4c369f8cd 100755 --- a/scripts/seed-database/container.sh +++ b/scripts/seed-database/container.sh @@ -18,7 +18,19 @@ mkdir -p /tmp # Create sync.sql file for all our comnands which will be executed in a single transaction touch '/tmp/sync.sql' -tables=(flows users teams flow_document_templates team_members team_themes) +tables=( + # Mandatory tables + flows + users + teams + flow_document_templates + team_members + team_themes + # Optional tables + # Please comment in if working on a feature and you require example data locally + # You will need to manually grant select permissions to the github_actions on production, and update main.sql + # feedback +) # run copy commands on remote db for table in "${tables[@]}"; do diff --git a/scripts/seed-database/write/feedback.sql b/scripts/seed-database/write/feedback.sql new file mode 100644 index 0000000000..833bf886f8 --- /dev/null +++ b/scripts/seed-database/write/feedback.sql @@ -0,0 +1,70 @@ +-- insert feedback overwriting conflicts +CREATE TEMPORARY TABLE sync_feedback ( + id integer, + team_id integer, + flow_id uuid, + created_at timestamptz, + node_id text, + device jsonb, + user_data jsonb, + user_context text, + user_comment text, + feedback_type text, + status text, + node_type text, + node_data jsonb +); + +\copy sync_feedback FROM '/tmp/feedback.csv' WITH (FORMAT csv, DELIMITER ';'); + +INSERT INTO + feedback ( + id, + team_id, + flow_id, + created_at, + node_id, + device, + user_data, + user_context, + user_comment, + feedback_type, + status, + node_type, + node_data + ) +SELECT + id, + team_id, + flow_id, + created_at, + node_id, + device, + user_data, + user_context, + user_comment, + feedback_type, + status, + node_type, + node_data +FROM + sync_feedback ON CONFLICT (id) DO +UPDATE +SET + id = EXCLUDED.id, + team_id = EXCLUDED.team_id, + flow_id = EXCLUDED.flow_id, + created_at = EXCLUDED.created_at, + node_id = EXCLUDED.node_id, + device = EXCLUDED.device, + user_data = EXCLUDED.user_data, + user_context = EXCLUDED.user_context, + user_comment = EXCLUDED.user_comment, + feedback_type = EXCLUDED.feedback_type, + status = EXCLUDED.status, + node_type = EXCLUDED.node_type, + node_data = EXCLUDED.node_data; +SELECT + setval('feedback_id_seq', max(id)) +FROM + feedback; \ No newline at end of file diff --git a/scripts/seed-database/write/main.sql b/scripts/seed-database/write/main.sql index 5ae353a990..4a75095dfd 100644 --- a/scripts/seed-database/write/main.sql +++ b/scripts/seed-database/write/main.sql @@ -1,3 +1,4 @@ +-- Mandatory tables \include write/users.sql \include write/teams.sql \include write/flows.sql @@ -5,4 +6,7 @@ \include write/published_flows.sql \include write/team_members.sql \include write/team_integrations.sql -\include write/team_themes.sql \ No newline at end of file +\include write/team_themes.sql + +-- Optional tables +-- \include write/feedback.sql \ No newline at end of file