Inventory system-scoped entities and rationalise tenant scoping strategy

Table of Contents

This page is a capture in the inbox bucket of the product backlog — a pre-sprint idea, not yet pulled into a sprint as a story.

What

Audit every codegen entity to determine its correct tenant-scoping strategy and apply it consistently. Currently two incompatible patterns coexist:

  1. Per-tenant copies (party_type approach) — seed data replicated to every tenant during provisioning. The repository filters by tenant_id naturally and each tenant sees its own copy. Works for entities that might need per-tenant variation.
  2. System-tenant context switch (old pricing_engine_type handler approach) — data lives only under the system tenant. The handler switches to sys_ctx via with_tenant(system()). All tenants read from one source. The template supports this via :system_tenant_validation:.

The new simple-lookup profile sets system_scope: false by default, implying per-tenant copies. But many entities (pricing engine types, instrument codes, etc.) are reference taxonomies that should never diverge per tenant — copying them is waste and a drift hazard.

Why

Discovered while applying safe drift to analytics-cpp: pricing_engine_type returned zero rows for Acme because its 44 system-tenant rows had no per-tenant copies, and the regenerated handler no longer had the system-tenant context switch that the old hand-authored handler hardcoded. Adding :system_tenant_validation: fixed it mechanically, but the real question is strategic: which entities genuinely need this treatment?

Key questions

  • Which entities need per-tenant copies vs system-tenant read-only?
  • For system-tenant entities that evolve with upstream (e.g. new ORE version adds engine types), how are writes gated?
  • Is :system_tenant_validation: the right mechanism, or do we need a finer-grained :read_only: true that allows writes under the system tenant only?
  • Should this be a profile axis rather than a per-entity flag?

References

See also

Emacs 29.3 (Org mode 9.6.15)