From 963a66ff73fd0108adb16b20de64e85ccd7d8671 Mon Sep 17 00:00:00 2001 From: Antonio Roberto Silva Date: Fri, 9 Dec 2022 07:45:53 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20Ajusta=20fun=C3=A7=C3=B5es=20de?= =?UTF-8?q?=20contagem=20de=20eventos=20em=20notifica=C3=A7=C3=B5es=20para?= =?UTF-8?q?=20utilizar=20o=20tipo=20correto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...357_update_notification_count_functions.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 services/catarse/db/migrate/20221209104357_update_notification_count_functions.rb diff --git a/services/catarse/db/migrate/20221209104357_update_notification_count_functions.rb b/services/catarse/db/migrate/20221209104357_update_notification_count_functions.rb new file mode 100644 index 000000000..892129dd6 --- /dev/null +++ b/services/catarse/db/migrate/20221209104357_update_notification_count_functions.rb @@ -0,0 +1,34 @@ +class UpdateNotificationCountFunctions < ActiveRecord::Migration[6.1] + def up + def change + execute <<-SQL + CREATE OR REPLACE FUNCTION public.delivered_count(project_post project_posts) RETURNS bigint + LANGUAGE sql AS $$ + select count(distinct notification_user) from sendgrid_events where notification_type = 'ProjectPostNotification' and notification_id IN + (select ppn.id from project_post_notifications ppn join project_posts pp on pp.id = ppn.project_post_id where pp.id = project_post.id) and event = 'delivered'; + $$; + + CREATE OR REPLACE FUNCTION public.open_count(project_post project_posts) RETURNS bigint + LANGUAGE sql AS $$ + select count(distinct notification_user) from sendgrid_events where notification_type = 'ProjectPostNotification' and notification_id IN + (select ppn.id from project_post_notifications ppn join project_posts pp on pp.id = ppn.project_post_id where pp.id = project_post.id) and event = 'open'; + $$; + SQL + end + + def down + execute <<-SQL + CREATE OR REPLACE FUNCTION public.delivered_count(project_post project_posts) RETURNS bigint + LANGUAGE sql AS $$ + select count(distinct notification_user) from sendgrid_events where notification_id IN + (select ppn.id from project_post_notifications ppn join project_posts pp on pp.id = ppn.project_post_id where pp.id = project_post.id) and event = 'delivered'; + $$; + + CREATE OR REPLACE FUNCTION public.open_count(project_post project_posts) RETURNS bigint + LANGUAGE sql AS $$ + select count(distinct notification_user) from sendgrid_events where notification_id IN + (select ppn.id from project_post_notifications ppn join project_posts pp on pp.id = ppn.project_post_id where pp.id = project_post.id) and event = 'open'; + $$; + SQL + end +end