-- Invalidate cached browser sessions after password, role or account-status
-- changes without storing session identifiers in the database.

SET @user_auth_version_sql = IF(
    EXISTS(
        SELECT 1 FROM information_schema.COLUMNS
        WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'users' AND COLUMN_NAME = 'auth_version'
    ),
    'SELECT 1',
    'ALTER TABLE users ADD COLUMN auth_version BIGINT UNSIGNED NOT NULL DEFAULT 1 AFTER password_hash'
);
PREPARE user_auth_version_statement FROM @user_auth_version_sql;
EXECUTE user_auth_version_statement;
DEALLOCATE PREPARE user_auth_version_statement;
