-- Backfill opening_type into magic_plan_window_ventilation from magic_plan_window.
-- Only rows with a non-null opening_type are backfilled; no ventilation row is
-- created for windows that never had one. The unique constraint on
-- magic_plan_window_id prevents duplicate rows if this runs more than once.

INSERT INTO magic_plan_window_ventilation (magic_plan_window_id, opening_type)
SELECT id, opening_type
FROM   magic_plan_window
WHERE  opening_type IS NOT NULL
ON CONFLICT (magic_plan_window_id) DO NOTHING;
