Repository navigation
feat(tenant): shared canonical-first organisationId ownership filter - #13
Merged
Merged
Conversation
Add a models-free, strings-only home for the organisationId migration's
canonical-first dual-read filter so hub-api and the pipeline services build the
exact same $or shape instead of each hardcoding it:
- CanonicalOrganisationField constant ("organisationId").
- MissingCanonicalOrganisation() predicate (reusable by index/backfill tooling).
- CanonicalFirstOwnership(organisationId, legacyField, legacyValue).
- TenantField{Legacy} per-collection descriptor with .Scope(org, legacyValue).
Callers resolve the ids via their own models helpers and pass strings, keeping
this package a dependency-light leaf. Additive; no existing consumer is affected
until it bumps the dependency and delegates its local helper here.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Add a models-free, strings-only home for the organisationId migration's
canonical-first dual-read filter so hub-api and the pipeline services build the
exact same $or shape instead of each hardcoding it:
- CanonicalOrganisationField constant ("organisationId").
- MissingCanonicalOrganisation() predicate (reusable by index/backfill tooling).
- CanonicalFirstOwnership(organisationId, legacyField, legacyValue).
- TenantField{Legacy} per-collection descriptor with .Scope(org, legacyValue).
Callers resolve the ids via their own models helpers and pass strings, keeping
this package a dependency-light leaf. Additive; no existing consumer is affected
until it bumps the dependency and delegates its local helper here.
…tabase into feat/canonical-organisation-id # Conflicts: # pkg/database/tenant.go # pkg/database/tenant_test.go
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change introduces a shared, canonical-first tenant ownership filter to support the ongoing
organisationIdmigration while preserving backward compatibility with legacy ownership fields.Previously, services needed to reimplement dual-read ownership logic independently, increasing the risk of inconsistent tenant isolation rules during the migration. By centralising this logic in
pkg/database, all services can now build the same ownership query shape from a single, tested implementation.The new helpers:
organisationIdfield for migrated documents.organisationIdvalues consistently to avoid partial-migration edge cases.TenantFieldabstraction so collections define legacy ownership fields once instead of duplicating string literals across query sites.This improves the project by making tenant scoping consistent, reducing migration risk, and creating a clear path to eventually remove legacy ownership handling once the backfill is complete. Comprehensive unit tests were added to lock down the expected query behaviour and prevent regressions.