SET @rvx_phone_attempts_exists := (
    SELECT COUNT(*)
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'leads'
      AND COLUMN_NAME = 'rvx_phone_attempts'
);

SET @ddl := IF(
    @rvx_phone_attempts_exists = 0,
    'ALTER TABLE leads ADD COLUMN rvx_phone_attempts INT NOT NULL DEFAULT 0 AFTER rvx_sync_attempts',
    'SELECT 1'
);

PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
