From ac8eb6d38d6ac1419d9227a40fef8157e82984a6 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 20 Dec 2025 21:01:34 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=A7=8D=E5=AD=90=E7=94=A8=E6=88=B7=20migration=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=94=99=E8=AF=AF=E7=9A=84=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 之前的 migration (20251220000000) 已经预留了 user_id 1-9 给系统账号 - 并设置序列从 10 开始 - 不应该再次重置序列,否则会覆盖之前的设置 修复: - 保留使用 user_id = 1(在预留范围内) - 移除序列重置代码 - 添加注释说明与之前 migration 的关系 这样确保: ✅ 系统账号使用 1-9 ✅ 普通用户从 10 开始(之前的设置) ✅ 不会产生 ID 冲突 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../migration.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/services/identity-service/prisma/migrations/20251220070000_add_system_seed_user/migration.sql b/backend/services/identity-service/prisma/migrations/20251220070000_add_system_seed_user/migration.sql index 81e0f4a7..54fa4785 100644 --- a/backend/services/identity-service/prisma/migrations/20251220070000_add_system_seed_user/migration.sql +++ b/backend/services/identity-service/prisma/migrations/20251220070000_add_system_seed_user/migration.sql @@ -1,8 +1,11 @@ -- CreateSystemSeedUser: 创建系统种子用户作为根推荐人 -- 这个用户只用于提供推荐码,不具备登录和其他功能 +-- +-- 注意:之前的 migration (20251220000000_set_user_id_sequence_start) +-- 已经预留了 user_id 1-9 给系统账号,所以这里使用 ID 1 是安全的 -- 插入系统种子用户 --- userId: 1 (固定ID) +-- userId: 1 (在预留范围 1-9 内) -- accountSequence: SYSTEM00001 (系统账号标识) -- referralCode: GENESIS (创世推荐码) -- nickname: 系统 (必填字段) @@ -18,7 +21,7 @@ INSERT INTO "user_accounts" ( "created_at", "updated_at" ) VALUES ( - 1, -- 使用 ID 1 作为系统用户 + 1, -- 使用预留的系统账号 ID 'SYSTEM00001', 'GENESIS', '系统', -- 必填字段 @@ -30,8 +33,5 @@ INSERT INTO "user_accounts" ( NOW() ) ON CONFLICT (user_id) DO NOTHING; -- 如果已存在则跳过 --- 重置自增序列,确保后续用户从 100000000 开始(之前的 migration 设置) --- 这样可以避免与系统用户 ID 冲突 -SELECT setval(pg_get_serial_sequence('user_accounts', 'user_id'), - GREATEST(100000000, (SELECT MAX(user_id) FROM user_accounts)), - false); +-- 注意:不需要重置序列,因为之前的 migration 已经设置序列从 10 开始 +-- 这样确保普通用户的 ID 从 10 开始,不会与系统账号(1-9)冲突