ADR 0051: Business Unit names in storage, claims and the public API
Status: Accepted. Supersedes the legacy client, tenant and OWNER vocabulary kept by
ADR 0014, ADR 0015
and ADR 0040.
ADR 0050 left these names as follow-up work.
Context
Karyo uses Company > Business Unit > Facility. Operational rows store only their Facility. Storage, identity and public API names still describe a Business Unit as a client or tenant. Karyo is unreleased and has no users, so a compatibility API or staged transition adds no value.
Decision
- Rename
clientstobusiness_unitsand retire the SYS row at id 0. - Rename the remaining Business Unit columns to
business_unit_id, event audiences included. Rename the warehouse-setup target column totarget_business_unit_id. - Keep key 0 in
system_properties,home_layoutsanddocument_templatesas the Company layer. It is not a Business Unit row. Configuration references expose a Company option to Company-level OPS principals. - Store
BUSINESS_UNIT_USERinstead ofOWNER. The production kind claim and the user-create API acceptopsandbusiness_unit_user, and refuseowner. Session projections return the enum name. - Default the Business Unit claim to
business_unit_id. Managed Keycloak uses the same user attribute. Both token clients and the agent scope emit it, and the legacy mappers are removed. - Use
businessUnitIdin public DTOs and events. Keep one Business Unit API,/api/v1/business-units, with its references and consistency routes. The console page is Business Units. - Remove the inert
onlyClientLocationoption. Facility scoping already determines every candidate. - Keep internal Kotlin names such as
Client,TenantEntityand entity, service and SPIclientId. Keep OAuth client identifiers unchanged, including theactor_client_idagent columns, which hold the token's OAuth client (azp), not a Business Unit id. The issuer-less test identity keeps its syntheticclient_idclaim.
A new global migration follows every table it touches, and earlier migrations stay immutable. The test-classpath fixture function uses the final storage names because it runs after every production migration.
Consequences
Storage, the business_unit_id claim and Keycloak attribute, the public API businessUnitId fields,
the removed /api/v1/clients and the BUSINESS_UNIT_USER kind use Business Unit vocabulary.
The CLIENT and SYSTEM source values and the System properties screen copy keep their current names.
Stored grants remain the only authority; the rename does not widen any reach.
Company-default configuration works without a synthetic organization row.
Existing developer principal rows receive the new kind in the same migration.
A claim of owner is refused with invalid-principal-kind-claim.
The demo tree, the pilot, the screenshots and the Atlas reset belong to the following change.
Alternatives considered
- Convert configuration key 0 to
NULL: rejected because it touches about 70 files and changes no behaviour. - A compatibility window, legacy API adapter, attribute-migration tool or staged cutover: not chosen; Karyo is unreleased and has no users.
- Rename the synthetic test claim
client_id: rejected because it touches about 240 test files and has no product effect. - Rename the agent
actor_client_idcolumns: rejected because they hold OAuth client ids.
Evidence
services/karyo-app/src/main/resources/db/migration/auth/V1602__business_unit_storage_and_principal_kind.sql,karyo.clients, karyo.business_units, karyo.item_data, karyo.item_substitutions, karyo.inactive_products, karyo.system_properties, karyo.home_layouts, karyo.document_templates, karyo.outbox_events, karyo.alert_deliveries, karyo.webhook_delivery, karyo.warehouse_setup_runs, karyo.storage_strategies, karyo.principals- renames the table, columns and principal kind.services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt,PrincipalSecurityIdentityAugmentor.parsePrincipalKind- the strict kind parser that refusesowner.services/karyo-app/src/main/resources/application.yaml,karyo.identity.claims.business-unit- the default claimbusiness_unit_id.services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/api/v1/BusinessUnitResource.kt,BusinessUnitResource.references- the references and consistency routes.services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/api/v1/HomeLayoutResource.kt,HomeLayoutResource.targetClient- key 0 resolves to the Company layer without a row lookup.services/karyo-app/src/test/kotlin/com/karyo/auth/BusinessUnitStorageTest.kt,BusinessUnitStorageTest- a fresh schema has final names and no SYS row.services/karyo-app/src/test/kotlin/com/karyo/app/auth/ClaimRuleTest.kt,ClaimRuleTest.asCaller- a legacyownerclaim is refused.services/karyo-app/src/test/kotlin/com/karyo/webhooks/relay/DeliveryTest.kt,DeliveryTest.reload- a delivered payload carriesbusinessUnitId.services/karyo-app/src/test/kotlin/com/karyo/auth/BusinessUnitResourceTest.kt,BusinessUnitResourceTest- Company is an option but never a listed Business Unit.