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

chore: Feedback sync script (example) #3160

Merged
merged 1 commit into from
May 17, 2024
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
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
Copy link
Member

Choose a reason for hiding this comment

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

👍

# 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
Loading