Skip to content

Commit

Permalink
add user to kpi_definition (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisiphos3 authored Oct 28, 2023
1 parent 7dcb13e commit fd19b6f
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ALTER TABLE public.kpi_definition
ADD created_by uuid not null default '2eca1eb1-2876-4625-ab7b-ce5342343f08';

ALTER TABLE public.kpi_definition
ALTER COLUMN created_by SET DEFAULT auth.uid ();

CREATE OR REPLACE VIEW
public.kpi_definition_with_latest_values as
select
Expand All @@ -17,6 +23,7 @@ select
t1.latest_value,
t1.latest_user_id,
t1.latest_standardized_date,
kd.formula,
t1.cumulative_value,
c.circle_name,
t.target_id,
Expand All @@ -30,6 +37,10 @@ from
circle_kpi_definition ckd
join kpi_definition kd
on ckd.kpi_id = kd.kpi_id
left join circle c
on ckd.circle_id = c.circle_id
left join target t
on ckd.kpi_id = t.kpi_id and ckd.circle_id = t.circle_id
left join (
select *
from
Expand All @@ -46,13 +57,7 @@ from
from
kpi_values_period_standardized) sq
where rank = 1) t1
on ckd.kpi_id = t1.kpi_id
join circle c
on t1.circle_id = c.circle_id
and ckd.circle_id = t1.circle_id
left join target t
on kd.kpi_id = t.kpi_id
and ckd.circle_id = t.circle_id
on ckd.kpi_id = t1.kpi_id and ckd.circle_id = t1.circle_id
LEFT JOIN (
SELECT kpi_id, circle_id, value as previous_value from(
SELECT kpi_id, circle_id, rank () over (
Expand All @@ -65,7 +70,7 @@ from
ON t1.kpi_id = previous_period.kpi_id and t1.circle_id = previous_period.circle_id
order by
kpi_id,
ckd.circle_kpidef_id;
ckd.circle_kpidef_id;

CREATE or REPLACE VIEW
public.kpi_values_period_standardized as
Expand Down Expand Up @@ -130,5 +135,4 @@ order by
standardized_date desc,
t1.circle_id,
t1.created_at desc
) as sq;

) as sq;

0 comments on commit fd19b6f

Please sign in to comment.