lablup / lablup/backend.ai

[Domain] Move model_cards.domain FK to model_cards.domain_id

Open
#11,723 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 ``model_cards.domain`` (string, → ``domains.name``) to a new ``model_cards.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 ``model_cards.domain_id`` UUID column (NOT NULL). Backfill via join on ``domains.name``. Drop legacy ``domain → domains.name`` FK (``ON DELETE RESTRICT``); create new ``domain_id → domains.id`` FK with the same ``RESTRICT`` semantics. Downgrade reverses.

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

3. Create / update specs: add ``domain_id: DomainID`` to ``ModelCardCreatorSpec`` in ``repositories/model_card/creators.py``. ``build_row`` populates both columns.

4. API entry point: ``api/adapters/model_card/adapter.py::create`` resolves ``domain_id`` via ``ResolveDomainIDByNameAction`` before constructing the spec.

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

Contributor guide

Open the contributing guide

Research direction

Start with the Alembic revision whose parent is fdc9d6ac49b4, then inspect ModelCardRow, repositories/model_card/creators.py, and api/adapters/model_card/adapter.py. Update the direct ModelCardRow fixtures named in the issue and run the affected tests. Done means the migration backfills domain_id, preserves the legacy column without its FK, reverses cleanly on downgrade, and the ORM, creator, adapter, and tests agree.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.