SET @avatar_url_column_exists := (
  SELECT COUNT(*)
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'users'
    AND COLUMN_NAME = 'avatar_url'
);

SET @avatar_url_statement := IF(
  @avatar_url_column_exists = 0,
  'ALTER TABLE users ADD COLUMN avatar_url VARCHAR(2048) NULL AFTER display_name',
  'SELECT 1'
);

PREPARE avatar_url_stmt FROM @avatar_url_statement;
EXECUTE avatar_url_stmt;
DEALLOCATE PREPARE avatar_url_stmt;
