Files
fourge-portal/supabase/migrations/20260408025500_normalize_submission_versions.sql
T
Krao Hasanee eee0885811 Fix file sharing load speed and move error; misc updates
- Remove recursive directory size calculations (single Seafile API call per list)
- Remove 'Used in this location' usage display
- Fix move using v2 per-type endpoints instead of broken batch endpoint
- Send entry type from frontend for correct move routing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-13 14:20:38 -04:00

25 lines
777 B
SQL

with affected_tasks as (
select s.task_id
from public.submissions s
group by s.task_id
having min(s.version_number) filter (where s.type <> 'amendment') = 1
and count(*) filter (where s.type <> 'amendment' and s.version_number = 0) = 0
)
update public.submissions s
set version_number = s.version_number - 1
from affected_tasks a
where s.task_id = a.task_id;
with corrected_versions as (
select
s.task_id,
coalesce(max(s.version_number) filter (where s.type <> 'amendment'), 0) as corrected_current_version
from public.submissions s
group by s.task_id
)
update public.tasks t
set current_version = cv.corrected_current_version
from corrected_versions cv
where t.id = cv.task_id
and t.current_version is distinct from cv.corrected_current_version;