refactor(workspace): 移除 data_residency 字段(后端) - #98
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis change removes workspace data residency from admin and console contracts, services, persistence, API formatting, and tests. Reversible migrations drop the database column and restore it during rollback. ChangesWorkspace data residency removal
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/platform_console_backend_api_test.go (1)
824-832: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert that
data_residencyis absent from the response.This test should lock in the contract being removed.
Proposed test assertion
if created["type"] != "workspace" || created["name"] != workspaceName || created["display_color"] != "`#1A8961`" || created["color"] != "`#1A8961`" { t.Fatalf("created workspace = %#v, want source-compatible workspace shape", created) } + if _, exists := created["data_residency"]; exists { + t.Fatalf("created workspace = %#v, data_residency must be omitted", created) + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/platform_console_backend_api_test.go` around lines 824 - 832, Update the workspace creation response assertions in the test around created and workspaceID to verify that the created map does not contain the data_residency field, preserving the existing source-compatible shape checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/platform_console_backend_api_test.go`:
- Around line 824-832: Update the workspace creation response assertions in the
test around created and workspaceID to verify that the created map does not
contain the data_residency field, preserving the existing source-compatible
shape checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 27f43cfa-c042-44e6-8a92-0fa76ebd96af
📒 Files selected for processing (12)
internal/admin/domain_workspace.gointernal/admin/dto.gointernal/admin/service.gointernal/db/admin.gointernal/db/console_api_keys.gointernal/db/migrations/00018_drop_workspace_data_residency.sqlinternal/platform/console.gointernal/platformapi/console_api_keys.gointernal/platformapi/platform_aliases.gotests/admin_api_test.gotests/platform_console_backend_api_test.gotests/platform_email_login_api_test.go
💤 Files with no reviewable changes (4)
- internal/platformapi/platform_aliases.go
- tests/admin_api_test.go
- internal/admin/service.go
- internal/admin/domain_workspace.go
There was a problem hiding this comment.
DuckPR reviewer: opencode
Model: anthropic/glm-5.2
✅ No new issues found.
Reviewed changes — 本 PR 从后端移除 workspaces.data_residency 列及其在 admin / console / db / platform 四层中的所有处理逻辑,并同步更新相关测试。
- 新增
00018_drop_workspace_data_residency.sqlmigration,以drop column if exists data_residency删除列,并在Down中按原默认值恢复列。 - 移除 admin 工作区 API 的
data_residency字段,包括createWorkspaceRequest/updateWorkspaceRequest/workspaceResponse以及internal/admin/domain_workspace.go中的 encode / decode / validate 辅助函数。 - 移除 console 工作区模型和 API 中的
data_residency,包括platform.ConsoleWorkspace、ConsoleWorkspaceDataResidency以及formatConsoleWorkspace/normalizeConsoleWorkspaceDataResidency。 - 更新
internal/db层读写,AdminWorkspace/CreateAdminWorkspace/UpdateAdminWorkspace/ArchiveAdminWorkspace/CreateConsoleWorkspace/ListConsoleWorkspaces不再扫描或写入data_residency。 - 调整三处集成测试,不再发送或断言
data_residency。
anthropic/glm-5.2 | 𝕏
There was a problem hiding this comment.
DuckPR reviewer: opencode
Model: anthropic/glm-5.2
✅ 无新问题。
Reviewed changes — 本次新增提交仅补充了设计文档,系统记录了移除 workspaces.data_residency 字段的完整设计决策、影响范围、兼容取舍、前后端协调与回滚方案。
- 新增设计文档
docs/design/be/workspace-data-residency-removal.md,覆盖背景、数据模型与 migration、API 合同兼容取舍、前后端合并顺序、测试计划与回滚。
anthropic/glm-5.2 | 𝕏
|
|
Drop the workspaces.data_residency column and all residency handling across admin, console, db, and platform layers. This field was a leftover from aligning with the upstream Anthropic workspace API and is no longer required. - migration 00018 drops workspaces.data_residency - remove residency fields/types from ConsoleWorkspace, AdminWorkspace - strip data_residency from console and admin DTOs and responses - update tests to stop asserting residency normalization
Record the decision, data-model/API impact, frontend/backend coordination, and rollback path for removing the legacy data_residency / geo field.
8a54edc to
dc6e07e
Compare
There was a problem hiding this comment.
DuckPR reviewer: opencode
Model: anthropic/glm-5.2
Important
合并 main 的 UUID 重构后,设计文档没有跟上:文档只描述了 00031,并断言「00031 会把列删掉,最终 schema 不含该列」,但这句在合并后已经不成立。详见下方 inline 评论。代码本身的两个 migration 都是必需且正确的。
Reviewed changes — 本次合并 origin/main 的 UUID 重构后,workspaces 表在 00036 被整体重建(建新表 → 拷贝 data_residency → drop 旧表 → 改名),导致 00031 删掉的列又回来了。新增的 00047_drop_workspace_data_residency_after_uuid_rebuild.sql 在重建之后再次删除该列,是正确且必需的;同时 schema.go legacy bootstrap 也已同步移除该列。
- 新增
00047_drop_workspace_data_residency_after_uuid_rebuild.sql—— 在00036_use_uuid_workspace_organization_reference.sql重建workspaces表后再次执行drop column if exists data_residency,确保最终 schema 不含该列(00036在新表定义与insert ... select中都带回了该列)。 schema.golegacy bootstrap 同步移除data_residency—— 从create table与alter table add column两处删除,与 migration 结果一致。internal/db/admin.go→internal/db/admin_workspaces.go—— admin workspace 数据访问随 UUID 重构拆分为独立文件,AdminWorkspace结构、SQL 与参数映射中不再含data_residency。internal/admin/service.go—— 随 UUID 重构改用principal.OrganizationUUID,CreateWorkspace/UpdateWorkspace/workspaceFromRecord均不再触碰 residency。
anthropic/glm-5.2 | 𝕏
| - migration `00031` 使用 `drop column if exists`,对已应用旧迁移的库与全新库都安全。 | ||
| - `internal/db/schema.go` 是 legacy bootstrap 文本 schema(仅 `migrateLegacyTextIDSchema` 使用),按项目规则不修改;其内部仍保留旧列定义,但 `Migrate()` 在 goose migration 之后执行,`00031` 会把列删掉,最终 schema 不含该列。 |
There was a problem hiding this comment.
00031,并断言「00031 会把列删掉,最终 schema 不含该列」——但 00036_use_uuid_workspace_organization_reference.sql 会整体重建 workspaces 表(建 workspaces_uuid_refs 时重新定义了 data_residency jsonb not null default ...,并在 insert ... select 中拷贝 w.data_residency,然后 drop 旧表、改名),因此 00031 删掉的列在 00036 之后会重新出现。真正完成最终删除的是本 PR 新增的 00047_drop_workspace_data_residency_after_uuid_rebuild.sql,而文档完全没有提及它。
按 AGENTS.md「修改 schema 变更…必须同步更新 docs/design/」的要求,需要把 00047 补进文档,并修正「00031 会把列删掉」这句不再成立的论断(说明 UUID 重建会带回该列、00047 负责重建后再次删除)。
Technical details
# 设计文档未同步 `00047` migration
## Affected sites
- `docs/design/be/workspace-data-residency-removal.md:51` — 只提及 `00031`,声称它让最终 schema 不含该列
- `docs/design/be/workspace-data-residency-removal.md:67` — 影响范围小节同样只列 `00031`
- `docs/design/be/workspace-data-residency-removal.md:119` — 回滚小节只描述 `00031` 的 Down
- `internal/db/migrations/00036_use_uuid_workspace_organization_reference.sql:31,47,97,113` — UUID 重建 workspaces 表时在新表定义与 copy 中带回 `data_residency`
- `internal/db/migrations/00047_drop_workspace_data_residency_after_uuid_rebuild.sql` — 文档未提及的第二次 drop
## Required outcome
- 文档「数据模型与 migration」小节需要说明存在两个 drop migration,以及 `00047` 存在的原因(`00036` 重建表时带回该列)
- 修正「`00031` 会把列删掉,最终 schema 不含该列」这句论断
- 回滚小节补充 `00047` 的 Down 行为(与 `00031` 一致,恢复带默认值的列)
## Suggested approach
最小改动:在「数据模型与 migration」小节增补一条 bullet 说明 `00036` 会重建 `workspaces` 表并带回 `data_residency`,因此需要 `00047` 在重建之后再次删除;并把「最终 schema 不含该列」的归因从 `00031` 改为 `00047`。回滚小节同理补充 `00047`。There was a problem hiding this comment.
DuckPR reviewer: opencode
Model: anthropic/glm-5.2
Important
设计文档仍未同步 00047 migration——详见下方「设计文档未更新 00047 migration」。
Reviewed changes — 本次新增提交(886c0e5)将 origin/main 的 Yourbatis mapper 重构合并进来;residency 移除相关的代码改动很小,主要是一个新增的 workspace 行映射单测。
- 合并 main 的 Yourbatis 重构 ——
internal/db/console_api_keys.go的 API key 数据访问被改写为 Yourbatis mapper(来自 main 的 PR #200/#202/#203,非本 PR 作者改动);workspace SQL 路径仍保留 sqlx,data_residency移除未受影响。 - 新增
console_workspaces_sqlx_test.go—— 单测验证consoleWorkspaceRow.workspace()的 UUID / external ID / tags 映射,间接覆盖 residency 字段已不在行结构中。
⚠️ 设计文档未更新 00047 migration
上一轮 review(73beee2)已指出:docs/design/be/workspace-data-residency-removal.md 第 51-52 行仍断言「00031 会把列删掉,最终 schema 不含该列」,但合并 main 的 UUID 重构后这句已不成立——00036_use_uuid_workspace_organization_reference.sql 重建 workspaces 表时会重新带回 data_residency 列(新表定义与 insert ... select 都包含它),真正完成最终删除的是本 PR 的 00047。本次增量提交仍未修正该文档,且影响范围小节(第 44 行)与回滚小节(第 119 行)同样只提 00031。
Technical details
# 设计文档未同步 `00047` migration
## Affected sites
- `docs/design/be/workspace-data-residency-removal.md:51` — 声称 `00031` 单独让最终 schema 不含该列
- `docs/design/be/workspace-data-residency-removal.md:44` — 影响范围小节只列 `00031`
- `docs/design/be/workspace-data-residency-removal.md:119` — 回滚小节只描述 `00031` 的 Down
- `internal/db/migrations/00036_use_uuid_workspace_organization_reference.sql:31,42,47,97,108,113` — UUID 重建时在新表定义与 copy 中带回 `data_residency`
- `internal/db/migrations/00047_drop_workspace_data_residency_after_uuid_rebuild.sql` — 文档未提及的第二次 drop
## Required outcome
- 「数据模型与 migration」小节说明存在两个 drop migration,以及 `00047` 存在的原因(`00036` 重建表时带回该列)
- 把「最终 schema 不含该列」的归因从 `00031` 改为 `00047`
- 回滚小节补充 `00047` 的 Down 行为(与 `00031` 一致,恢复带默认值的列)
## Suggested approach
最小改动:在「数据模型与 migration」小节增补一条 bullet 说明 `00036` 会重建 `workspaces` 表并带回 `data_residency`,因此需要 `00047` 在重建之后再次删除;并把「最终 schema 不含该列」的归因从 `00031` 改为 `00047`。影响范围与回滚小节同理补充 `00047`。anthropic/glm-5.2 | 𝕏

问题背景
#93 中维护者反馈:工作区的 geo / data_residency 功能是之前对齐原版 Anthropic 工作区 API 时遗留的,本项目不再需要,应整体移除。
为避免单 PR 范围过大,拆分为两个 PR 共同完成 #93:本 PR 为后端部分,前端部分另开 PR。
方案
彻底移除
workspaces.data_residency列及所有相关处理逻辑,覆盖 admin / console / db / platform 四层:00018_drop_workspace_data_residency.sql,drop column if exists data_residency(幂等,Down 可恢复默认值)platform.ConsoleWorkspace/db.AdminWorkspace移除DataResidency与DataResidencySettings字段data_residency字段,以及 normalize / format / decode / encode 等辅助函数与类型别名兼容性取舍
移除该字段会偏离 Anthropic workspace API 的
data_residency合同。这是有意的:本项目不提供多地域推理,保留该字段只会产生无意义的默认值噪音。前端 PR 将同步移除 UI 与类型。改动文件
internal/db/migrations/00018_drop_workspace_data_residency.sql(新增)internal/admin/domain_workspace.go、internal/admin/dto.go、internal/admin/service.gointernal/db/admin.go、internal/db/console_api_keys.gointernal/platform/console.go、internal/platformapi/console_api_keys.go、internal/platformapi/platform_aliases.gotests/admin_api_test.go、tests/platform_email_login_api_test.go、tests/platform_console_backend_api_test.go验证方式
go build ./...golangci-lint run(仓库.golangci.yml):0 issuesgo test ./internal/admin/ ./internal/db/ ./tests/ -count=1:通过just dead-code/just complexity/just duplicates:均通过Refs #93
Summary by CodeRabbit
Changes
Documentation