fix(identity-service): 设置 user_id 自增序列从 10 开始

- 添加数据库 migration 设置 user_id 序列起始值为 10
- 保留 user_id 1-9 给系统账户使用
- 修复用户注册时的唯一约束冲突错误
- 序列值安全检查:仅在当前值 < 10 时重置

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-20 18:16:08 -08:00
parent cdb55ec4cb
commit 3f904ab6f7
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
-- Set user_id sequence to start from 10
-- This reserves user IDs 1-9 for system accounts
-- Check current sequence value
DO $$
DECLARE
current_val BIGINT;
BEGIN
-- Get current sequence value
SELECT last_value INTO current_val FROM user_accounts_user_id_seq;
-- Only reset if current value is less than 10
IF current_val < 10 THEN
-- Set sequence to start from 10
-- Using setval with false means next nextval() will return 10
PERFORM setval('user_accounts_user_id_seq', 10, false);
RAISE NOTICE 'Sequence reset to start from 10';
ELSE
RAISE NOTICE 'Sequence already at % (>= 10), no reset needed', current_val;
END IF;
END $$;