-- 迁移：auth.users 新增 avatar_url 字段
-- 日期：2026-03-24
-- 原因：小程序登录时获取微信头像，保存到服务器后存储相对路径
-- 影响：后端 /api/xcx/me 返回 avatar_url；小程序个人页、审核页显示头像

BEGIN;

ALTER TABLE auth.users
    ADD COLUMN IF NOT EXISTS avatar_url VARCHAR(500);

COMMENT ON COLUMN auth.users.avatar_url IS '用户头像相对路径（如 avatars/123.jpg），由 chooseAvatar 上传后保存';

COMMIT;

-- ── 回滚 ──
-- BEGIN;
-- ALTER TABLE auth.users DROP COLUMN IF EXISTS avatar_url;
-- COMMIT;

-- ── 验证 ──
-- 1. SELECT column_name, data_type, character_maximum_length
--    FROM information_schema.columns
--    WHERE table_schema='auth' AND table_name='users' AND column_name='avatar_url';
--    期望：avatar_url, character varying, 500
--
-- 2. SELECT id, nickname, avatar_url FROM auth.users LIMIT 5;
--    期望：avatar_url 列存在，值为 NULL
--
-- 3. SELECT col_description(
--      (SELECT oid FROM pg_class WHERE relname='users' AND relnamespace=(SELECT oid FROM pg_namespace WHERE nspname='auth')),
--      (SELECT ordinal_position FROM information_schema.columns WHERE table_schema='auth' AND table_name='users' AND column_name='avatar_url')
--    );
--    期望：包含 'chooseAvatar' 关键词
