chore(scripts): create_gallery_test_users.go add setval + dev.sh starbook cleanup

- create_gallery_test_users.go 末尾循环 setval 序列重置 (config 4.3-C):
  user/asset/booth_slots; exhibitions 移除 (无硬编码 id + 序列不一定存在);
  booth_slots PK=slot_id 用 MAX(slot_id) 正确列名;
- dev.sh: 移除 starbookService 引用 (config 4.2 残留)。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
zerosaturation 2026-07-24 14:04:45 +08:00
parent e1fb138e8e
commit 3cce70ec2e
2 changed files with 32 additions and 9 deletions

View File

@ -21,7 +21,7 @@ cleanup() {
fi
# 清理所有 PID 文件并杀服务进程
for service in gateway activityService galleryService socialService assetService userService taskService starbookService aiChatService statisticService notificationService moderationService; do
for service in gateway activityService galleryService socialService assetService userService taskService aiChatService statisticService notificationService moderationService; do
pkill -9 -f "$service" 2>/dev/null || true
rm -f "/tmp/dev_sh_${service}.pid" "/tmp/dev_sh_${service}_restart" "/tmp/dev_sh_${service}.lock"
echo -e "${YELLOW} 🛑 $service 已停止${NC}"
@ -344,7 +344,6 @@ start_watcher() {
--exclude='galleryService$' \
--exclude='activityService$' \
--exclude='taskService$' \
--exclude='starbookService$' \
--exclude='aiChatService$' \
--exclude='notificationService$' \
--exclude='moderationService$' &
@ -362,7 +361,7 @@ start_watcher() {
--exclude='galleryService$' \
--exclude='activityService$' \
--exclude='taskService$' \
--exclude='starbookService$' \
--exclude='aiChatService$' \
--exclude='aiChatService$' \
--exclude='notificationService$' \
--exclude='moderationService$' &
@ -429,13 +428,13 @@ echo ""
> /tmp/dev_sh_watchers.tmp
# 清理残留 PID 文件(上次非正常退出可能留下)
for service in activityService galleryService socialService assetService userService taskService gateway starbookService aiChatService statisticService notificationService moderationService; do
for service in activityService galleryService socialService assetService userService taskService gateway aiChatService statisticService notificationService moderationService; do
rm -f "/tmp/dev_sh_${service}.pid" "/tmp/dev_sh_${service}_restart"
done
# 停止现有服务(清理环境)
echo -e "${YELLOW}🛑 停止现有服务...${NC}"
for service in gateway userService socialService assetService galleryService activityService taskService starbookService aiChatService statisticService notificationService moderationService; do
for service in gateway userService socialService assetService galleryService activityService taskService aiChatService statisticService notificationService moderationService; do
pkill -9 -f "$service" 2>/dev/null || true
done
sleep 1
@ -465,7 +464,6 @@ build_service "socialService" "services/socialService" "services/socialService
build_service "galleryService" "services/galleryService" "services/galleryService/galleryService"
build_service "activityService" "services/activityService" "services/activityService/activityService"
build_service "taskService" "services/taskService" "services/taskService/taskService"
build_service "starbookService" "services/starbookService" "services/starbookService/starbookService"
build_service "aiChatService" "services/aiChatService" "services/aiChatService/aiChatService"
build_service "statisticService" "services/statisticService" "services/statisticService/statisticService"
build_service "notificationService" "services/notificationService" "services/notificationService/notificationService"
@ -490,7 +488,6 @@ echo -e "${GREEN}🚀 启动 taskService...${NC}"
echo $! > "/tmp/dev_sh_taskService.pid"
sleep 2
echo -e "${GREEN}✅ taskService 已启动 (PID: $(cat /tmp/dev_sh_taskService.pid), 端口: 20006)${NC}"
start_service "starbookService" "services/starbookService/starbookService" 20007 1 0
start_service "aiChatService" "services/aiChatService/aiChatService" 20008 1 1
start_service "statisticService" "services/statisticService/statisticService" 20009 1 1
start_service "notificationService" "services/notificationService/notificationService" 20010 1 0
@ -507,7 +504,6 @@ start_watcher "socialService" "services/socialService" "services/socialS
start_watcher "galleryService" "services/galleryService" "services/galleryService/galleryService" 20004 1 0
start_watcher "activityService" "services/activityService" "services/activityService/activityService" 20005 1 0
start_watcher "taskService" "services/taskService" "services/taskService/taskService" 20006 1 0
start_watcher "starbookService" "services/starbookService" "services/starbookService/starbookService" 20007 1 0
start_watcher "aiChatService" "services/aiChatService:pkg/proto" "services/aiChatService/aiChatService" 20008 1 1
start_watcher "statisticService" "services/statisticService:pkg/proto" "services/statisticService/statisticService" 20009 1 1
start_watcher "notificationService" "services/notificationService:pkg/proto/notification" "services/notificationService/notificationService" 20010 1 0
@ -527,7 +523,6 @@ echo " - Asset Service: tri://localhost:20003"
echo " - Gallery Service: tri://localhost:20004"
echo " - Activity Service: tri://localhost:20005"
echo " - Task Service: tri://localhost:20006"
echo " - Starbook Service: tri://localhost:20007"
echo " - Statistic Service: tri://localhost:20009 (port+1000=21009 healthz)"
echo " - Notification Service: tri://localhost:20010 (port+1000=21010 healthz)"
echo " - Moderation Service: tri://localhost:20011 (port+1000=21011 healthz)"

View File

@ -167,4 +167,32 @@ ON CONFLICT (asset_id) DO UPDATE SET slot_id = EXCLUDED.slot_id, expire_at = EXC
fmt.Printf("-- GET /api/v1/galleries/%d (查看用户1的展馆)\n", user1ID)
fmt.Printf("-- GET /api/v1/galleries/%d (查看用户2的展馆)\n", user2ID)
fmt.Println()
// ========================================
// 序列同步: 手动指定 PK 后必须 setval,否则后续 GORM/autoIncrement
// 插入会因序列落后于 MAX(PK) 而报 duplicate key。
// (CLAUDE.md: PostgreSQL 序列同步规则, 强制)
//
// 表 PK / 序列对应关系(以数据库 schema 为准):
// users.id -> users_id_seq
// assets.id -> assets_id_seq
// booth_slots.slot_id -> booth_slots_slot_id_seq (PK 是 slot_id, 不是 id)
//
// exhibitions 不硬编码 id(用 ON CONFLICT (asset_id) 兜底),无序列滞后
// 风险;且 exhibitions_id_seq 是否存在取决于表是否真有 id 列 — 默认
// 不写,避免 relation does not exist 中断整批 SQL。
// ========================================
fmt.Println("-- ========================================")
fmt.Println("-- 序列同步 (硬编码 PK 后必须 setval,见 CLAUDE.md)")
fmt.Println("-- ========================================")
setvalStatements := []struct{ seq, col, tbl string }{
{"users_id_seq", "id", "users"},
{"assets_id_seq", "id", "assets"},
{"booth_slots_slot_id_seq", "slot_id", "booth_slots"},
}
for _, s := range setvalStatements {
fmt.Printf(`SELECT setval('%s', (SELECT MAX(%s) FROM %s));`, s.seq, s.col, s.tbl)
fmt.Println()
}
fmt.Println()
}