-- POS (QR-code) checkout mode.
-- Makes payer nullable (assigned at scan-time) and adds checkout_mode discriminator.
-- Idempotent: safe to run even if the column already exists.

ALTER TABLE checkout_requests
  MODIFY COLUMN payer_account_id BIGINT UNSIGNED NULL;

SET @_cnt = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'checkout_requests' AND COLUMN_NAME = 'checkout_mode');
SET @_sql = IF(@_cnt = 0, 'ALTER TABLE checkout_requests ADD COLUMN checkout_mode ENUM(''standard'', ''pos'') NOT NULL DEFAULT ''standard'' AFTER created_by_user_id', 'SELECT 1');
PREPARE _stmt FROM @_sql;
EXECUTE _stmt;
DEALLOCATE PREPARE _stmt;
