Skip to Content
FeaturesOrganization Trees

Organization Trees

An organization can sit inside another organization, to any depth, and this page is the exact set of rules for what that means: what a caller standing at one level reads and writes, what a descendant inherits from the organizations above it, and what moving, deleting and suspending an organization do to everything beneath it. The Organizations page covers why the level exists and how a product is built on it; read that first.

Depth lives in your data

An organization has one optional parent. Give it one and it sits inside that parent’s subtree: a reseller with its own clients, a franchise with its branches, a region with the brands under it. Leave it out and the organization is a root of the project.

There is no depth limit. Depth is not a setting, a plan feature or a declared number of levels, so a project may have no organizations at all, one flat row of them, or a tree twelve deep, and nothing is declared or migrated to go from one shape to the next. Ancestry is kept in a closure table beside the organizations, rebuilt in the same transaction as any change to a parent, so “is this organization at or below that one” is always answered from the tree as it stands.

A project with no organizations behaves exactly as a project did before organizations existed. There is no enable step and no adoption path. The organizations a project has are the whole of the switch: the moment a caller stands in one, the rows it writes belong to that organization. Rows written before then stay project-shared for good (org_id is NULL), and nothing moves them into an organization later. The way to make an organization own data is to write it there.

Three placements are refused. The database refuses all three whichever path writes the parent, and through the API they answer:

PlacementAnswer
An organization under itselfFAILED_PRECONDITION: organization <id> cannot be its own parent
An organization under one of its own descendantsFAILED_PRECONDITION: organization <id> cannot be placed under <parent>, which is already inside its subtree
A parent that is not an organization of the same projectNOT_FOUND: parent organization not found, the same answer as a parent that does not exist

An organization is identified by its id. Names are free: two organizations, including two siblings, may share one, so keep the id.

What a level is

Every row on an organization-scoped table carries an org_id. Standing in an organization, three kinds of row are in play:

Tierorg_id on the row
The project-shared tierNULL: written by a caller standing in no organization
The organization’s own rowsthe id of the organization the caller stands in
Its descendants’ rowsthe id of any organization anywhere beneath it

A caller stands in an organization in one of four ways: a key confined to it, a project key naming it with X-Org-Id or by its address with X-Org-Url, a signed-in person’s request naming it the same way, or the console at its address. Every one of them resolves to the same claim, and the rules below are the same for all of them.

Rows reach down

What a caller reads and what it may change are deliberately different sets.

VerbThe rows it reaches, standing in organization B
SELECTthe project-shared tier, B’s own rows, and the rows of every organization beneath B
INSERTB’s own rows: a new row is stamped with B’s id
UPDATEB’s own rows, and the organization-owned records B owns in the project-shared tier
DELETEB’s own rows, and the organization-owned records B owns in the project-shared tier

Five tables take a row’s organization from what the row is about rather than from the writer: notifications, notification preferences and device tokens carry their owner’s organization, and events and event deliveries carry their subject’s. Everywhere else the stamp decides.

So an organization reads its whole subtree and changes only its own rows. A reseller’s key lists every client’s orders and cannot edit or delete one of them, and it cannot edit or delete a project-shared row either, unless that row is an organization-owned record the reseller itself owns. Reading down is reporting and support; writing belongs to whoever stands in the organization that owns the row. Nothing below an organization reaches up: a client reads none of its reseller’s rows and none of its siblings’.

Two consequences are worth designing for before they surprise anyone:

  • “This organization must edit the rows of one beneath it” is answered by standing in that one, not by widening the parent’s write. A membership reaches downward, so a user who operates the parent may select any organization beneath it and act there. A project key names it with X-Org-Id, and a console user selects it.
  • “This child must edit its parent’s rows” is answered by an assignment at the parent: a membership in the parent organization, which reaches the parent and everything beneath it. There is no setting that lets a descendant write upward.

The list of tables that take the level is on the Organizations page, with the policy terms copied from the emitted migration.

Standing in no organization

A caller with no organization claim reads the project-shared tier only. The read term has four ways to admit a row: org_id IS NULL, org_id equal to the claim, the cross-organization reach header, and membership of the claim’s subtree. With no claim and no reach header, the second compares against NULL and is never true, the third is never true, and the subtree of no organization is empty, so the term collapses to org_id IS NULL. An absent claim narrows to the shared tier; it never opens to every organization. The one way to read every organization of a project in one request is X-Org-Reach: project.

Definitions inherit down

Definitions travel in the opposite direction to rows. These carry the level:

  • models and operations
  • locales and context dimensions
  • user sign-in providers
  • design tokens
  • notification categories
  • variant catalog entries

Standing in organization B, a caller reads the project’s definitions, the definitions of every organization above B, and B’s own. It never reads a descendant’s definitions or a sibling’s. A reseller defines a model once and every client beneath it receives it, while a client’s private model stays out of its reseller’s schema.

Deepest wins. When the same key is defined at more than one level on B’s path, B’s callers get the definition from the level nearest to B: B’s own, then its parent’s, and so on up to the project’s. The order is the organization’s position on its path, never the order the definitions were created in.

A definition is changed only at the level that owns it. Standing in B, a definition B inherits from the project or from an ancestor is read-only. To change it for B and everything beneath B, define one with the same key at B. A caller standing in an organization that tries to change a project-level definition is refused with PERMISSION_DENIED, and the message says the definition belongs to the project, which sits above the organization.

Some configuration belongs to the project as a whole and is refused to a caller standing in an organization: project configurations and applying a configuration bundle (which is what foir push does), the project’s own settings, and publishing the project schema.

The GraphQL schema a caller is served is composed for its organization’s path. An organization for which neither it nor any organization above it defines anything is served the project’s schema unchanged.

Moving an organization

MoveOrganization gives an organization a new parent, or makes it a root when no parent is sent. From the terminal it is foir orgs move. The whole subtree comes with it: every descendant keeps its own parent, so the branch arrives intact and only where it hangs changes.

It is its own call rather than a field on the update, because it changes who reaches the moved rows and what the moved organizations inherit.

Who may move what. The caller must reach both the organization being moved and the destination. A key confined to an organization moves organizations only within its own subtree. An organization outside the caller’s reach answers NOT_FOUND, exactly as one that does not exist, and so does a named parent it cannot read. Asking a confined key to make an organization a root of the project, including the organization it is confined to, answers PERMISSION_DENIED.

What changes, at once. The closure is rebuilt in the same transaction as the parent change, so there is no moment at which the row layer answers from the old tree. From the next request on, everything in the moved subtree resolves through its new position: which ancestors read its rows, which definitions it inherits, which caps bind it and whether an ancestor’s suspension covers it. Its usage moves with it too, because each organization’s figures count only itself.

What a move revokes: nothing. No key, session, membership or grant is revoked or rewritten. A credential names an organization by its id rather than by its path, so keys and sessions standing anywhere in the subtree keep working and pick up the new position on their next request. That is deliberate: a move is also how a misplaced organization is corrected, and a correction that cut off every live storefront beneath it would never be made.

What is purged. Every cached answer that depended on the old position is dropped after the move commits: the response cache and the lookup cache for the moved subtree and for both the ancestors it left and the ancestors it joined, and the compiled schema for the project on both the draft and published channels.

A move fires one ORGANIZATION_MOVED event, for the organization that moved. A move to the parent it already has changes nothing and fires nothing.

Deleting a subtree

Deleting an organization deletes its whole subtree. There is no reading of the request that promotes the children to roots, because that would be a containment change with nothing raised to notice it.

Scheduling the deletion puts the organization and every organization beneath it on the same 30-day clock. Each one carries the status and the deadline on its own row and fires its own ORGANIZATION_DELETION_SCHEDULED, so every organization that will be destroyed is named while cancelling it is still possible. Nothing is removed until the window closes.

Cancelling reaches the same set and puts each organization back to the status it held before the schedule, so an organization that was suspended in its own right stays suspended. An organization inside one that is still scheduled for deletion or suspended cannot be made active on its own: the answer is FAILED_PRECONDITION, naming the organization above it that is not active.

When the window closes, each organization is purged in its own right, children before parents: a parent’s row cannot be removed while any organization beneath it remains. Keys confined to a purged organization are deleted with it. Records owned by an organization through the organization owner plane are not in the organization’s partition and are left in place.

Suspending a subtree

An organization’s effective status is the strictest status on its path to the root, so suspending an organization covers everything beneath it without writing to a single descendant. Resume it and the organizations that were stopped only by that suspension are back as they were; one suspended in its own right stays suspended.

Suspending removes no row, from the suspended organization or from anything beneath it. A suspension fires one ORGANIZATION_SUSPENDED, for the organization that was suspended, and none for the organizations beneath it, so treat everything beneath it as suspended too.

Foir does not email an organization’s members about its lifecycle. Suspension, a scheduled deletion, its cancellation and resuming send nothing to them. Your application tells its own users, from the organization events. The project’s own people who could have made the change, apart from whoever made it, get a notice in the console’s inbox.

Counting organizations

Every organization in a tree is a whole organization, wherever it sits. Each one counts its own rows in per-organization usage and never its descendants’, so the figures add up to the project’s totals. A cap set on an organization binds its whole subtree and is measured over that subtree, so adding a level beneath a capped organization is never a way around the cap.

Last updated on