-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve routing insights view (2) (#18566)
- Loading branch information
1 parent
a8c29b5
commit 21694c0
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
packages/prisma/migrations/20250109161330_update_routing_form_response/migration.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,72 @@ | ||
CREATE OR REPLACE VIEW "RoutingFormResponse" AS | ||
SELECT | ||
r.id, | ||
r.response, | ||
( | ||
SELECT jsonb_object_agg( | ||
key, | ||
CASE | ||
WHEN jsonb_typeof(value->'value') = 'string' | ||
THEN jsonb_build_object( | ||
'label', value->'label', | ||
'value', lower((value->>'value')::text) | ||
) | ||
ELSE value | ||
END | ||
) | ||
FROM jsonb_each(r.response::jsonb) | ||
) as "responseLowercase", | ||
f.id as "formId", | ||
f.name as "formName", | ||
f."teamId" as "formTeamId", | ||
f."userId" as "formUserId", | ||
b.uid as "bookingUid", | ||
b.status as "bookingStatus", | ||
CASE b.status | ||
WHEN 'accepted' THEN 1 | ||
WHEN 'pending' THEN 2 | ||
WHEN 'awaiting_host' THEN 3 | ||
WHEN 'cancelled' THEN 4 | ||
WHEN 'rejected' THEN 5 | ||
END as "bookingStatusOrder", | ||
b."createdAt" as "bookingCreatedAt", | ||
b."startTime" as "bookingStartTime", | ||
b."endTime" as "bookingEndTime", | ||
(SELECT | ||
json_agg( | ||
json_build_object( | ||
'name', a.name, 'timeZone', a."timeZone", 'email', a.email | ||
) | ||
) | ||
FROM "Attendee" a | ||
WHERE "a"."bookingId" = b.id | ||
) as "bookingAttendees", | ||
u.id as "bookingUserId", | ||
u.name as "bookingUserName", | ||
u.email as "bookingUserEmail", | ||
u."avatarUrl" as "bookingUserAvatarUrl", | ||
COALESCE( | ||
( | ||
SELECT | ||
ar."reasonString" | ||
FROM "AssignmentReason" ar | ||
WHERE ar."bookingId" = b.id | ||
LIMIT 1 | ||
), | ||
'' | ||
) as "bookingAssignmentReason", | ||
COALESCE( | ||
( | ||
SELECT | ||
LOWER(ar."reasonString") | ||
FROM "AssignmentReason" ar | ||
WHERE ar."bookingId" = b.id | ||
LIMIT 1 | ||
), | ||
'' | ||
) as "bookingAssignmentReasonLowercase", | ||
r."createdAt" as "createdAt" | ||
FROM "App_RoutingForms_FormResponse" r | ||
LEFT JOIN "App_RoutingForms_Form" f ON r."formId" = f.id | ||
LEFT JOIN "Booking" b ON r."routedToBookingUid" = b.uid | ||
LEFT JOIN "users" u ON b."userId" = u.id |