planner v2 vc. porovnani
Some checks failed
CI and deploy / migration-check (push) Failing after 20s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-15 23:03:32 +02:00
parent d89d8b1e3a
commit 7490ac3d70
11 changed files with 900 additions and 29 deletions

View File

@@ -5,7 +5,8 @@ create or replace function ems.fn_planning_run_commit(
p_horizon_start timestamptz,
p_horizon_end timestamptz,
p_run_meta jsonb,
p_intervals jsonb
p_intervals jsonb,
p_activate_run boolean default true
)
returns int
language plpgsql
@@ -29,7 +30,7 @@ begin
p_site_id,
p_horizon_start,
p_horizon_end,
'draft',
case when p_activate_run then 'draft' else 'comparison' end,
nullif(trim(p_run_meta->>'run_type'), ''),
nullif(trim(p_run_meta->>'triggered_by'), ''),
case
@@ -128,13 +129,16 @@ begin
update ems.planning_run
set status = 'superseded'
where site_id = p_site_id
where p_activate_run
and site_id = p_site_id
and status = 'active'
and id <> v_run_id;
update ems.planning_run
set status = 'active'
where id = v_run_id;
if p_activate_run then
update ems.planning_run
set status = 'active'
where id = v_run_id;
end if;
return v_run_id;
end;