-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollback drop distribution summary view
- Loading branch information
1 parent
c923528
commit 5190e1a
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
supabase/migrations/20241106092256_rollback_drop_distribution_summary_view.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,40 @@ | ||
CREATE OR REPLACE VIEW "public"."distribution_verifications_summary" WITH ( security_barrier | ||
) AS | ||
WITH base_counts AS ( | ||
SELECT | ||
dv.distribution_id, | ||
dv.user_id, | ||
dv.type, | ||
SUM(dv.weight) AS total_weight, | ||
jsonb_agg(dv.metadata) AS combined_metadata | ||
FROM | ||
distribution_verifications dv | ||
LEFT JOIN distribution_verification_values dvv ON dvv.distribution_id = dv.distribution_id | ||
AND dvv.type = dv.type | ||
WHERE | ||
dv.user_id = auth.uid() | ||
GROUP BY | ||
dv.distribution_id, | ||
dv.user_id, | ||
dv.type | ||
) | ||
SELECT | ||
dvv.distribution_id, | ||
COALESCE(bc.user_id, auth.uid()) AS user_id, | ||
array_agg(ROW (dvv.type, COALESCE(bc.total_weight, 0), dvv.fixed_value, dvv.bips_value, COALESCE(bc.combined_metadata, '[]'::jsonb))::verification_value_info) AS verification_values, | ||
array_agg(ROW (dvv.type, CASE WHEN (COALESCE(dvv.multiplier_min, 1.0) = 1.0 | ||
AND COALESCE(dvv.multiplier_max, 1.0) = 1.0 | ||
AND COALESCE(dvv.multiplier_step, 0.0) = 0.0) | ||
OR COALESCE(bc.total_weight, 0) = 0 THEN | ||
NULL | ||
ELSE | ||
LEAST(dvv.multiplier_min +((COALESCE(bc.total_weight, 1) - 1) * dvv.multiplier_step), dvv.multiplier_max) | ||
END, dvv.multiplier_min, dvv.multiplier_max, dvv.multiplier_step, COALESCE(bc.combined_metadata, '[]'::jsonb))::multiplier_info) AS multipliers | ||
FROM | ||
distribution_verification_values dvv | ||
LEFT JOIN base_counts bc ON bc.distribution_id = dvv.distribution_id | ||
AND bc.type = dvv.type | ||
GROUP BY | ||
dvv.distribution_id, | ||
COALESCE(bc.user_id, auth.uid()); | ||
|
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