Repository navigation
Open
Labels
Description
Background
Domain.default_content_guard was added in #7992 as a ForeignKey directly on the Domain model. With multi-database support (#7862), this foreign key becomes a problem:
Domainis a control-plane model and lives in the default database.ContentGuardis domain-scoped (pulp_domainFK) and lives in the satellite database selected by the domain'sdatabase_alias.
A FK from Domain → ContentGuard therefore crosses database boundaries. We want to avoid cross-database joins entirely.
Proposal
Remove default_content_guard from Domain and store the mapping in a new domain-scoped table that lives in the same database as the content guard it references.
New model
class DomainDefaultContentGuard(BaseModel):
pulp_domain = models.OneToOneField(
"Domain", default=get_domain_pk, on_delete=models.CASCADE
)
content_guard = models.ForeignKey(
"ContentGuard", on_delete=models.CASCADE
)pulp_domainis a one-to-one (at most one default guard per domain) and is what thePulpDomainRouteruses to route the row to the correct satellite DB. It resolves locally becauseDomainrows are replicated into satellite DBs (domain_sync.py).content_guardlives in that same satellite DB, so the lookup never crosses a database.on_delete=CASCADEoncontent_guard: deleting a content guard removes its default-mapping row (observable result unchanged from the previousSET_NULL: the domain simply has no default).
Changes
- Model (
app/models/domain.py): drop thedefault_content_guardfield; add the new model. - Migration: create the new table, data-migrate existing
Domain.default_content_guardvalues into it, then drop the column. - Serializer (
app/serializers/domain.py): keep the publicdefault_content_guardanddefault_content_guard_prnfields and the "guard must belong to this domain" validation; back them with the new table. - Viewset (
app/viewsets/domain.py): replaceselect_related("default_content_guard")with the appropriate join/prefetch through the new table. - Auto-assignment (
app/models/publication.py:835): resolve the default guard via the new table instead ofpulp_domain.default_content_guard_id(remains a local lookup). - Tests: update existing functional (
test_crud_domains.py) and unit (test_domain.py) coverage to the new path.
Non-goals
- No change to the public REST API surface (
default_content_guard/default_content_guard_prnbehave as today). - No multi-db router/replication work here — this only restructures the relationship so it's ready for initial commit for multidb #7862.
Activity
Simplify multi-database RBAC to database-local roles and grants
Simplify multi-database RBAC to database-local roles and grants