From edd8c53c3a8a39fcd3c7b7e5643b63e379e0142a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=BF=E4=BA=91=E7=A7=8B=E6=9C=88?= <15273589815@163.com> Date: Fri, 11 Sep 2026 21:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20create=5Ftest=5Fuser=20?= =?UTF-8?q?=E9=87=8C=E5=86=99=E5=8F=8D=E7=9A=84=E7=90=86=E7=94=B1=EF=BC=9A?= =?UTF-8?q?sys=5Fuser=5Frole=20=E6=9C=89=E5=94=AF=E4=B8=80=E9=94=AE?= =?UTF-8?q?=EF=BC=8C=E5=85=88=E6=B8=85=E5=90=8E=E6=8F=92=E6=98=AF=E4=B8=BA?= =?UTF-8?q?=E4=BA=86=E6=94=AF=E6=8C=81=E6=94=B9=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/create_test_user.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/create_test_user.py b/tools/create_test_user.py index 3aa3e46..4dd99f4 100644 --- a/tools/create_test_user.py +++ b/tools/create_test_user.py @@ -143,7 +143,10 @@ async def upsert_user( "now": now, }, ) - # 角色绑定先清后插:`sys_user_role` 没有唯一约束,直接插会堆重复行。 + # 角色绑定先清后插。表上其实**有** `uk_sys_user_role (user_id, role_id)` 唯一键 + # (`tools/generate_baseline_sql.py:128`),所以直接 INSERT 不会堆重复行 —— + # 先清的理由是**支持改角色**:不清的话换角色会在表里留下两条绑定, + # `IdentityService` 解析出的 roles 就变成两个(既是 customer 又是 admin)。 await session.execute( text("DELETE FROM sys_user_role WHERE user_id = :user_id"), {"user_id": user_id} )