-- RAJAWALI CORE SYSTEM
-- Sprint 2 — HOTFIX: user avatar thumbnail column
-- Add nullable avatar_path to users table (idempotent)

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

SET @ddl := IF(
  @col_exists = 0,
  'ALTER TABLE users ADD COLUMN avatar_path VARCHAR(255) NULL AFTER email',
  'SELECT 1'
);

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