lablup / lablup/backend.ai

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

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

2. ORM: ``session_templates`` is declared via ``sa.Table`` in ``models/session_template.py``. Add ``sa.Column("domain_id", GUID, sa.ForeignKey("domains.id"), nullable=False)`` and remove the FK declaration from the legacy ``domain_name`` column.

3. Repository / db_source: ``repositories/template/db_source/db_source.py::create_task_templates`` and ``create_cluster_template`` raw INSERT queries gain a ``"domain_id": domain_id`` value. Their callers (``repositories/template/repository.py`` and ``services/template/service.py``) thread ``domain_id`` through. Add ``domain_id: DomainID`` to ``CreateTaskTemplateAction`` and ``CreateClusterTemplateAction``.

4. API entry points: ``api/rest/session_template/handler.py`` and ``api/rest/cluster_template/handler.py`` resolve ``domain_id`` via ``ResolveDomainIDByNameAction`` before constructing the action. The handlers need ``DomainProcessors`` injected in their constructor; update ``api/rest/tree.py`` accordingly.

5. Tests: update fixtures that insert into ``session_templates`` 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-6131

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.