[Domain] Move endpoint_tokens.domain FK to endpoint_tokens.domain_id
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
Goal
Move the foreign key reference from ``endpoint_tokens.domain`` (string, → ``domains.name``) to a new ``endpoint_tokens.domain_id`` (UUID, → ``domains.id``). The legacy ``domain`` string column is retained without a FK constraint; removal is deferred to BA-6122. ``domains`` keeps ``name`` as PK in this story — the PK swap is BA-6046.
Scope
1. Alembic: single revision, parent ``down_revision = fdc9d6ac49b4``. Add ``endpoint_tokens.domain_id`` UUID column (NOT NULL). Backfill via join on ``domains.name``. Drop legacy ``domain → domains.name`` FK (which used ``ON DELETE CASCADE``); create new ``domain_id → domains.id`` FK with the same ``CASCADE`` semantics. Downgrade reverses.
2. ORM: add ``domain_id: Mapped[DomainID]`` on ``EndpointTokenRow``; keep ``domain`` column (drop only its FK clause). Update the explicit ``__init__`` on ``EndpointTokenRow`` to accept ``domain_id``.
3. Create / update specs: add ``domain_id: DomainID`` to both ``EndpointTokenCreatorSpec`` in ``repositories/model_serving/creators.py`` AND the duplicate one in ``repositories/deployment/creators/token.py``. ``build_row`` populates both columns.
4. API / service callers:
- ``services/model_serving/services/model_serving.py`` (legacy token creation) — sources ``domain_id`` from ``EndpointData.domain_id`` (added by BA-6127).
- ``services/deployment/service.py`` (newer access-token creation) — sources ``domain_id`` from ``DeploymentInfo.metadata.domain_id`` (added by BA-6127).
5. Tests: update fixtures that construct ``EndpointTokenRow`` directly so ``domain_id`` is populated.
Parallelism
Coordinates with BA-6127 (endpoints) only via ``EndpointData.domain_id`` / ``DeploymentMetadata.domain_id`` exposure — additive and safe in either merge order. Independent of the other 8 stories.
Out of scope
- ``domains`` PK swap — BA-6046.
- Legacy column drop — BA-6122.
JIRA Issue: BA-6128
Contributor guide
Assessment
This issue has not been assessed yet.