select setval('base_sys_user_id_seq', 10000000, false);


-- 1. 恢复原自增，解除依赖
ALTER TABLE base_sys_user
ALTER COLUMN id SET DEFAULT nextval('base_sys_user_id_seq');

-- 2. 清理旧函数
DROP FUNCTION IF EXISTS next_8digit_rand_id() CASCADE;

-- 3. 【终极版】不重复 + 乱序 + 固定8位
CREATE OR REPLACE FUNCTION next_8digit_rand_id()
RETURNS bigint
LANGUAGE plpgsql VOLATILE
AS $$
DECLARE
  seq_val bigint;
BEGIN
  seq_val := nextval('base_sys_user_id_seq');
  RETURN 10000000 + ((seq_val * 1103515245 + 12345) # 58329) % 90000000;
END;
$$;

-- 4. 启用
ALTER TABLE base_sys_user
ALTER COLUMN id SET DEFAULT next_8digit_rand_id();
