feat(db): 同步种子用户与项目序列避免冷启动主键冲突
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
-- +goose Up
|
||||
-- 00011 显式插入 users/projects id 后同步序列,避免冷启动 duplicate key
|
||||
BEGIN;
|
||||
|
||||
SELECT setval(
|
||||
pg_get_serial_sequence('users', 'id'),
|
||||
COALESCE((SELECT MAX(id) FROM users), 1),
|
||||
true
|
||||
);
|
||||
|
||||
SELECT setval(
|
||||
pg_get_serial_sequence('projects', 'id'),
|
||||
COALESCE((SELECT MAX(id) FROM projects), 1),
|
||||
true
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- +goose Down
|
||||
-- 序列同步不可逆;Down 为空操作
|
||||
SELECT 1;
|
||||
Reference in New Issue
Block a user