lablup / lablup/backend.ai

[Domain] Move sessions.domain_name FK to sessions.domain_id

Open
#11,718 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
15h 13m
Merged PRs (30d)
368

Description

Goal

Move the foreign key reference from ``sessions.domain_name`` (string, → ``domains.name``) to a new ``sessions.domain_id`` (UUID, → ``domains.id``). The legacy ``domain_name`` 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 ``sessions.domain_id`` UUID column (NOT NULL). Backfill from ``domains`` via join on ``domains.name``. Drop the existing ``sessions.domain_name → domains.name`` FK. Create new ``sessions.domain_id → domains.id`` FK. Downgrade restores the legacy FK and drops the new column.

2. ORM: add ``domain_id: Mapped[DomainID]`` on ``SessionRow``; keep ``domain_name`` column (drop only its FK clause). The ``DomainRow → sessions`` relationship continues to back-populate via ``domain``.

3. Creators / updaters: ``SessionRow`` is built from ``SessionSpec`` in ``repositories/scheduler/creators.py``. Add ``domain_id: DomainID`` to ``SessionScope`` (``data/session/spec.py``) and ``SessionScopeDraft`` (``data/session/draft.py``); have the creator pass ``self.spec.scope.domain_id`` into the Row.

4. API entry points / sokovan: every place that builds a ``SessionScope`` / ``SessionScopeDraft`` from external input must resolve ``domain_id`` via ``ResolveDomainIDByNameAction`` and set the new field. Includes legacy ``manager/registry.py`` session enqueue paths and ``sokovan/deployment/deployment_draft_builder.py``.

5. Tests: update fixtures that construct ``SessionRow`` 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-6125

Contributor guide

Open the contributing guide

Research direction

Start with the Alembic revision whose parent is fdc9d6ac49b4, then inspect SessionRow and the SessionScope definitions in data/session/spec.py and data/session/draft.py. Trace repositories/scheduler/creators.py, manager/registry.py, and sokovan/deployment/deployment_draft_builder.py for external session construction, and update the named fixtures. Done means the migration backfills domain_id, switches the FK, preserves domain_name, and tests pass with populated domain_id values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, database
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.