-- Backfill submission_role for rows created before the API persisted the column.
-- Safe to run multiple times (only updates NULL roles).

UPDATE ptw_submissions s
INNER JOIN ptw_opening_closing_map m ON m.opening_sub_id = s.submission_id
SET s.submission_role = 'opening'
WHERE s.submission_role IS NULL;

UPDATE ptw_submissions s
INNER JOIN ptw_opening_closing_map m ON m.closing_sub_id = s.submission_id
SET s.submission_role = 'handback'
WHERE s.submission_role IS NULL;
