refactor(mcp-go): Profile 套雪花id+软删规约,补集成测试(还清 DB 规约欠债)
项目级 DB 规约(雪花字符串 id + created_at/updated_at + 软删索引)此前只在网关落地, mcp-go 的 sundynix_user_profile(Profile) 仍是旧复合主键 (user_id,key)、无 id/时间戳—— 本次对齐,全库统一。 - 新增 BaseModel + NewID(snowflake node=2,与网关 node=1 区分,避免共享 PG 中 id 冲突)。 - Profile 嵌 BaseModel:雪花 id 主键 + (user_id,key) 唯一索引。 - Upsert 改 OnConflict((user_id,key)),冲突覆盖 value 且保留原 id/created_at。 - 一次性迁移 migrateLegacyProfile:检测旧表(无 id 列)→ 备份偏好 → drop → 按新规约重建 → 回灌。 - 加 mcp-go 首个集成测试(store_test.go,gated on MEMORY_TEST_DSN): · TestBaseModelID 纯单测(id 非空/不重/BeforeCreate 补id不覆盖); · Integration:迁移后字段齐全 + Upsert 同键覆盖不新增 + id 稳定 + Get 渲染; · LegacyMigration:旧复合主键表 + 1 条偏好 → 迁移后 id 列存在、数据保留补新 id。 实测(docker postgres):三测全过,迁移日志确认旧偏好回灌保留 ✓。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,7 @@ require (
|
||||
github.com/blevesearch/zapx/v14 v14.3.10 // indirect
|
||||
github.com/blevesearch/zapx/v15 v15.3.13 // indirect
|
||||
github.com/blevesearch/zapx/v16 v16.1.5 // indirect
|
||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cockroachdb/errors v1.9.1 // indirect
|
||||
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
|
||||
|
||||
Reference in New Issue
Block a user