From 8c5dd97d638b0ad1d434d6cd93b3f50ede9a14e6 Mon Sep 17 00:00:00 2001 From: weichen Date: Sat, 12 Sep 2026 16:52:30 +0000 Subject: [PATCH] =?UTF-8?q?feat(db):=20=E5=90=8C=E6=AD=A5=E7=A7=8D?= =?UTF-8?q?=E5=AD=90=E7=94=A8=E6=88=B7=E4=B8=8E=E9=A1=B9=E7=9B=AE=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E9=81=BF=E5=85=8D=E5=86=B7=E5=90=AF=E5=8A=A8=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../00025_2026-09-13-sync-seed-sequences.sql | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 deploy/postgres/goose/00025_2026-09-13-sync-seed-sequences.sql diff --git a/deploy/postgres/goose/00025_2026-09-13-sync-seed-sequences.sql b/deploy/postgres/goose/00025_2026-09-13-sync-seed-sequences.sql new file mode 100644 index 00000000..6056c2c3 --- /dev/null +++ b/deploy/postgres/goose/00025_2026-09-13-sync-seed-sequences.sql @@ -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;