update public.submissions s
set signs = legacy.signs
from (
  select
    submission_id,
    jsonb_agg(
      jsonb_build_object(
        'sign_number', sign_number,
        'sign_name', sign_name,
        'sign_family', sign_family
      )
      order by sign_number
    ) as signs
  from public.submission_signs
  group by submission_id
) as legacy
where s.id = legacy.submission_id
  and (
    s.signs is null
    or s.signs = '[]'::jsonb
  );

drop table if exists public.submission_signs cascade;
