-- 为用户分配角色
-- 首先查询角色ID
SELECT id, name, display_name FROM roles;

-- 插入角色分配记录 (employee_id: sxn)
INSERT INTO user_roles (id, employee_id, role_id, source, assigned_at)
SELECT 'ur-sxn-agent', 'sxn', id, 'manual', NOW()
FROM roles WHERE name = 'agent'
ON CONFLICT DO NOTHING;

INSERT INTO user_roles (id, employee_id, role_id, source, assigned_at)
SELECT 'ur-sxn-admin', 'sxn', id, 'manual', NOW()
FROM roles WHERE name = 'admin'
ON CONFLICT DO NOTHING;

-- 验证
SELECT ur.employee_id, r.name as role_name, r.display_name
FROM user_roles ur
JOIN roles r ON ur.role_id = r.id
WHERE ur.employee_id = 'sxn';
