[Domain] Move groups.domain_name FK to groups.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 ``groups.domain_name`` (string, → ``domains.name``) to a new ``groups.domain_id`` (UUID, → ``domains.id``). The legacy ``domain_name`` string column is retained without a FK constraint; removal is deferred to BA-6122. ``domains`` itself keeps ``name`` as PK in this story — the PK swap on ``domains`` is BA-6046.
Scope
1. Alembic: single revision, parent ``down_revision = fdc9d6ac49b4``. Add ``groups.domain_id`` UUID column (NOT NULL — legacy column was NOT NULL). Backfill ``domain_id = domains.id`` via join on ``domains.name``. Drop the existing ``groups.domain_name → domains.name`` FK (which had ``CASCADE`` on both delete and update). Create new ``groups.domain_id → domains.id`` FK with the same ``CASCADE`` semantics. Provide downgrade.
2. ORM: add ``domain_id: Mapped[DomainID]`` on ``GroupRow``; keep ``domain_name`` column (drop only its FK clause).
3. Create / update specs: add ``domain_id: DomainID`` to ``GroupCreatorSpec``. ``GroupUpdaterSpec`` currently has no domain field — no change unless modify endpoints ever migrate a group across domains. Make ``build_row`` populate both columns.
4. API entry points: convert ``domain_name`` → ``domain_id`` via ``ResolveDomainIDByNameAction``. Affected: ``api/adapters/project/adapter.py``, ``api/gql_legacy/group.py``.
5. Repository call sites: ``repositories/domain/repository.py::_create_model_store_group`` already populates both columns (the FK column type changed but the kwarg is the same); audit other ``GroupRow(domain_name=...)`` call sites and add ``domain_id``.
6. Tests: update fixtures that construct ``GroupRow`` 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 — BA-6122.
JIRA Issue: BA-6124
Contributor guide
Research direction
Start with the Alembic revision using parent fdc9d6ac49b4, then inspect GroupRow, GroupCreatorSpec, build_row, and the affected API adapters. Audit _create_model_store_group and other GroupRow(domain_name=...) call sites, plus direct-construction fixtures. Done means the migration has upgrade and downgrade paths, all named call sites populate domain_id, and the relevant tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend, database, testing
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100