Skip to content

docs(protocol): 重写 schema.mdx「Multi-Tenant Schemas」为平台实际租户姿势 (#5746) - #5884

Merged
os-zhuang merged 1 commit into
mainfrom
claude/issue-5746-schema-mdx-tenancy
Aug 6, 2026
Merged

docs(protocol): 重写 schema.mdx「Multi-Tenant Schemas」为平台实际租户姿势 (#5746)#5884
os-zhuang merged 1 commit into
mainfrom
claude/issue-5746-schema-mdx-tenancy

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Closes #5746

content/docs/protocol/objectql/schema.mdx 的「Multi-Tenant Schemas」小节整段与平台事实不符,本 PR 按代码逐条重写。文件面只有这一页(docs-only,不产出 changeset)。

原文教的 vs 实际

原文 实测(origin/main
tenancy.tenantField: tenant_id + 手写 fields.tenant_id 租户列就是 registry 注入的 organization_idtenantField#5315(已合,fc5f536a1 / PR #5766)起没有默认值,未声明即 undefined,由 driver 回落 organization_id
reference: tenant 平台没有 tenant 对象;组织对象是 sys_organizationpackages/platform-objects/src/identity/sys-organization.object.ts:14),也正是注入列的 reference
「kernel 运行在 multi-tenant 模式(OS_MULTI_ORG_ENABLED=true)时,registry 才注入 organization_id 注入是无条件的(除 tenancy.enabled: false / systemFields.tenant: false / systemFields: false / managedBy: 'better-auth' 四种退出),只有该列的索引受 posture 影响:packages/objectql/src/registry.ts:421wantTenantindexed: opts.multiTenant
「注入到 every user object」 是每个未退出的已注册对象,不限用户自建对象
「默认的 tenant_isolation RLS policy 收敛读写」 那条通配 policy 已被 ADR-0095 D1 退役,租户墙改为 Layer 0(packages/plugins/plugin-security/src/tenant-layer.ts),先于业务 RLS 且与之 AND 合成、不共享 bypass 位
OS_MULTI_ORG_ENABLED 当现行开关 它是 LEGACY/DEMOTEDpackages/types/src/env.ts:89-122):仅当 OS_TENANCY_POSTURE 未设置时作为回落输入读取。现行开关是 OS_TENANCY_POSTURE(ADR-0105 D1,single / group / isolated

改法(取 PM 倾向的「平台默认姿势」)

主示例不再出现 tenantField:一个租户隔离的对象关于租户什么都不用声明。随后补三段正文:

  1. 注入条件与范围(未退出即注入;只有索引受 posture 影响),并给出真正的作者杠杆 —— tenancy.enabled: false退出示例(平台级 catalog);
  2. tenantField 只作为「租户列确实不是 organization_id」的逃生舱一笔带过(workspace_id,与 spec 自身 @examplecontent/docs/data-modeling/objects.mdx 措辞一致),并写明无默认值、且声明的列不存在时被忽略;
  3. 执行点改写为 Layer 0 + posture 谓词(single 惰性 / grouporganization_id IN accessible_org_ids / isolated 为按活动组织收敛),并指向已有的权威页 /docs/deployment/tenancy-modes,不在本页重复解释 posture 解析规则。

OS_MULTI_ORG_ENABLED 在新正文里一次都不出现 —— 它的 legacy 身份与解析表在 content/docs/deployment/tenancy-modes.mdxdeployment/environment-variables.mdx 已经写全,本页再提只会把降级过的开关重新教一遍。

校验

  • node scripts/check-nul-bytes.mjs(含 --self-test)✅ · check-doc-authoring ✅(362 files clean)· check-role-word ✅(ratchet 无新增)· docs-audit/check-audit-scope ✅(178 页在 scope)
  • packages/lintcheck:doc-formula-expressions ✅(self-test 11 cases + 22 个 formula 例子全绿)
  • packages/speccheck:skill-examples ✅(205 prose examples type-check)—— 本页那段 os:check 标记的 TS 块未被触碰,跑它是为了确认没被牵连
  • @mdx-js/mdx 单独编译改后的页面 ✅(内联代码里的 organization_id = ... 与跨行代码跨度都不会被当成 JSX)
  • 本页示例不在任何 YAML 样例编译门禁内(os:check 只覆盖 ts|typescript|tsx 块);docs-only ⇒ 无 changeset,PR 自带 skip-changeset

顺手记录(未在本 PR 修)

  • content/docs/plugins/packages.mdx:335 仍把 OS_MULTI_ORG_ENABLED=true 当启用 multi-org 的方式(够不到 group posture)→ 已单独开 issue
  • content/docs/protocol/kernel/config-resolution.mdx 通篇教 context.config.setTenant() / setUserPreference() / objectstack_tenant_config 表,仓库里零实现 → 已单独开 issue

Generated by Claude Code

The section taught three things the platform does not do:
`tenantField: tenant_id` with a hand-declared `tenant_id` lookup, a
`reference: tenant` target that does not exist (the organization object is
`sys_organization`), and `OS_MULTI_ORG_ENABLED` as the live switch plus a
default `tenant_isolation` RLS policy as the enforcement point.

Rewritten from the code: `organization_id` is registry-injected on every
non-opted-out object regardless of posture (only its index is posture-gated),
`tenancy.enabled: false` is the opt-out, `tenantField` carries no default
(#5315) and exists only for a genuinely non-`organization_id` column, and the
wall is Layer 0 (ADR-0095 D1) with the predicate chosen by
`OS_TENANCY_POSTURE` (ADR-0105 D1).
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectstack Ignored Ignored Aug 6, 2026 10:57am

Request Review

@github-actions github-actions Bot added the size/s label Aug 6, 2026
@os-zhuang os-zhuang added skip-changeset PR has no user-facing published change; bypasses the changeset gate and removed size/s labels Aug 6, 2026 — with Claude
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 6, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review August 6, 2026 11:05
@os-zhuang
os-zhuang added this pull request to the merge queue Aug 6, 2026
Merged via the queue into main with commit 5c3c30d Aug 6, 2026
28 of 29 checks passed
@os-zhuang
os-zhuang deleted the claude/issue-5746-schema-mdx-tenancy branch August 6, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation skip-changeset PR has no user-facing published change; bypasses the changeset gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

protocol/objectql/schema.mdx 的多租户小节教 tenant_id + legacy OS_MULTI_ORG_ENABLED,与平台的 organization_id / ADR-0120 词表不一致

2 participants