-- Add CHECKED_OUT to the VisitorStatus enum.
-- ALTER TYPE ... ADD VALUE in Postgres can't be run in the same transaction
-- as a statement that uses the new value, hence the COMMIT between.
ALTER TYPE "VisitorStatus" ADD VALUE IF NOT EXISTS 'CHECKED_OUT';

-- Migrate any ARRIVED rows that had checkedOutAt stamped (from the
-- pre-status auto-checkout sweep) over to the new terminal state.
-- Wrapped to handle the enum-value timing limitation gracefully.
COMMIT;

UPDATE "Visitor"
SET status = 'CHECKED_OUT'
WHERE status = 'ARRIVED' AND "checkedOutAt" IS NOT NULL;

BEGIN;
