add analytics (#162)

This commit is contained in:
KM Koushik
2025-05-11 23:34:21 +10:00
committed by GitHub
parent be7f030d75
commit b5ebd002e5
20 changed files with 1031 additions and 418 deletions

View File

@@ -0,0 +1,27 @@
BEGIN;
-- 1) Populate or update cumulated totals
INSERT INTO "CumulatedMetrics" (
"teamId",
"domainId",
"delivered",
"hardBounced",
"complained"
)
SELECT
du."teamId",
du."domainId",
SUM(du.delivered)::BIGINT AS delivered,
SUM(du."hardBounced")::BIGINT AS hardBounced,
SUM(du.complained)::BIGINT AS complained
FROM public."DailyEmailUsage" du
GROUP BY
du."teamId",
du."domainId"
ON CONFLICT ("teamId","domainId") DO UPDATE
SET
"delivered" = EXCLUDED."delivered",
"hardBounced" = EXCLUDED."hardBounced",
"complained" = EXCLUDED."complained";
COMMIT;