-- Optional password on a website's Portal (only a BCrypt hash is kept). Idempotent: safe to re-run.
-- If the table is busy, this gives up after 15 seconds (and can simply be run again) instead of waiting and holding up the app.
SET SESSION lock_wait_timeout = 15;
SET @col_exists = (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'dim_web_sites' AND COLUMN_NAME = 'portal_password_hash'
);
SET @sql = IF(@col_exists = 0,
    'ALTER TABLE dim_web_sites ADD COLUMN portal_password_hash VARCHAR(100) NULL',
    'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
