[Domain] Move sgroups_for_domains.domain FK to sgroups_for_domains.domain_id
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
Goal
Move the foreign key reference from ``sgroups_for_domains.domain`` (string, → ``domains.name``) to a new ``sgroups_for_domains.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 ``sgroups_for_domains.domain_id`` UUID column (NOT NULL). Backfill via join on ``domains.name``. Drop legacy ``domain → domains.name`` FK (``ON DELETE CASCADE``, ``ON UPDATE CASCADE``); create new ``domain_id → domains.id`` FK with the same semantics. Add an index ``ix_sgroups_for_domains_domain_id`` to mirror the existing legacy-column index. The composite ``uq_sgroup_domain`` UNIQUE constraint stays on ``(scaling_group, domain)`` — it will be moved to ``(scaling_group, domain_id)`` in BA-6122 when the legacy column is dropped. Downgrade reverses.
2. ORM: add ``domain_id: Mapped[DomainID]`` on ``ScalingGroupForDomainRow``; keep ``domain`` column (drop only its FK clause). Leave the ``uq_sgroup_domain`` UniqueConstraint on the legacy column for this story.
3. Create / update specs: add ``domain_id: DomainID`` to ``ScalingGroupForDomainCreatorSpec`` in ``repositories/scaling_group/creators.py``. ``build_row`` populates both columns.
4. Repository call sites that raw-INSERT into ``ScalingGroupForDomainRow`` from ``repositories/domain/repository.py`` (``create_domain_node``, ``modify_domain_node``): populate both ``domain`` and ``domain_id``.
5. API entry points: ``api/gql_legacy/scaling_group.py::AssociateScalingGroupWithDomain`` and ``AssociateScalingGroupsWithDomain`` resolve ``domain_id`` via ``ResolveDomainIDByNameAction`` before constructing the spec.
6. Tests: update fixtures that construct ``ScalingGroupForDomainRow`` directly so ``domain_id`` is populated.
Parallelism
Independent of the other 9 referencing-table stories. Alembic head consolidation happens under BA-6046.
Out of scope
- ``domains`` PK swap — BA-6046.
- Legacy column drop and unique-constraint relocation — BA-6122.
JIRA Issue: BA-6132
Contributor guide
Assessment
This issue has not been assessed yet.