Skip to content

Move Domain's default content guard into a dedicated table (multi-db prep) #8303

Open

Description

@dkliban

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:

  • Domain is a control-plane model and lives in the default database.
  • ContentGuard is domain-scoped (pulp_domain FK) and lives in the satellite database selected by the domain's database_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_domain is a one-to-one (at most one default guard per domain) and is what the PulpDomainRouter uses to route the row to the correct satellite DB. It resolves locally because Domain rows are replicated into satellite DBs (domain_sync.py).
  • content_guard lives in that same satellite DB, so the lookup never crosses a database.
  • on_delete=CASCADE on content_guard: deleting a content guard removes its default-mapping row (observable result unchanged from the previous SET_NULL: the domain simply has no default).

Changes

  • Model (app/models/domain.py): drop the default_content_guard field; add the new model.
  • Migration: create the new table, data-migrate existing Domain.default_content_guard values into it, then drop the column.
  • Serializer (app/serializers/domain.py): keep the public default_content_guard and default_content_guard_prn fields and the "guard must belong to this domain" validation; back them with the new table.
  • Viewset (app/viewsets/domain.py): replace select_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 of pulp_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_prn behave as today).
  • No multi-db router/replication work here — this only restructures the relationship so it's ready for initial commit for multidb #7862.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions