Skip to content

Commit

Permalink
chore: Feedback sync script [skip pizza]
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed May 17, 2024
1 parent ce6e37e commit 8d74478
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
14 changes: 13 additions & 1 deletion scripts/seed-database/container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions scripts/seed-database/write/feedback.sql
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion scripts/seed-database/write/main.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
-- Mandatory tables
\include write/users.sql
\include write/teams.sql
\include write/flows.sql
\include write/flow_document_templates.sql
\include write/published_flows.sql
\include write/team_members.sql
\include write/team_integrations.sql
\include write/team_themes.sql
\include write/team_themes.sql

-- Optional tables
-- \include write/feedback.sql

0 comments on commit 8d74478

Please sign in to comment.