lablup / lablup/backend.ai

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

Open
#11,719 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 ``kernels.domain_name`` (string, → ``domains.name``) to a new ``kernels.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 ``kernels.domain_id`` UUID column (NOT NULL). Backfill via join on ``domains.name``. Drop legacy FK, create new ``domain_id → domains.id`` FK. Downgrade reverses.

2. ORM: add ``domain_id: Mapped[DomainID]`` on ``KernelRow``; keep ``domain_name`` column (drop only its FK clause).

3. Creators: ``KernelRow`` is built from ``KernelSpec`` / parent ``SessionSpec`` in ``repositories/scheduler/creators.py``. Read ``self.spec.scope.domain_id`` from the spec — this depends on the ``SessionScope.domain_id`` field added by BA-6125 (sessions story). If the sessions story has not landed first, this story includes the same ``SessionScope`` / ``SessionScopeDraft`` change as a duplicate; whoever merges second drops the duplicate.

4. Tests: update fixtures that construct ``KernelRow`` directly so ``domain_id`` is populated.

Parallelism

Independent of the other 9 referencing-table stories at the database / FK layer. At the spec layer it shares ``SessionScope.domain_id`` with BA-6125 — merging the two does not conflict because the field is additive.

Out of scope

- ``domains`` PK swap — BA-6046.

- Legacy column drop — BA-6122.

JIRA Issue: BA-6126

Contributor guide

Open the contributing guide

Research direction

Start with the Alembic revision whose parent is fdc9d6ac49b4, then inspect KernelRow and repositories/scheduler/creators.py. Check the SessionScope.domain_id dependency from BA-6125 and update fixtures that construct KernelRow directly. Done means the migration backfills and constrains domain_id, the ORM and creators populate it, and downgrade reverses the database changes.

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
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.