lablup / lablup/backend.ai

[ScalingGroup] Migrate FK references to `scaling_group_id` and swap PK to `id`

Open
#11,621 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

Goal

Migrate the remaining scaling-group name FK references to scaling_group_id and atomically swap the scaling_groups primary key from name to id.

Scope reduced (2026-07-06): sessions/kernels/agents columns were carved out to sibling issues - sessions.scaling_group_name id column was added by BA-6644 and is dropped by BA-6713; kernels.resource_group_id is added by BA-6707; agents.resource_group_id is added by BA-6708. This story covers what remains.

Remaining referencing columns

- sgroups_for_domains.scaling_group
- sgroups_for_groups.scaling_group
- sgroups_for_keypairs.scaling_group
- endpoints.resource_group
- resource_presets.scaling_group_name (custom join, no FK constraint)
- reader migration for kernels/agents (switch queries, fair-share partial indexes and aggregates from name to resource_group_id, then drop the legacy kernels.scaling_group / agents.scaling_group columns)

Scope

- Alembic: add UUID FK columns to the remaining tables, backfill from name -> id, replace FK constraints (preserve cascade rules), drop legacy columns.
- Same Alembic revision: drop PK on scaling_groups.name, add PK on scaling_groups.id, demote name to UNIQUE.
- ORM: update each model, including ResourcePresetRow custom join condition.
- Repository: update queries across repositories/scaling_group/, repositories/agent/, repositories/fair_share/, repositories/deployment/, repositories/resource_preset/. Replace session.get(ScalingGroupRow, name) with explicit selects.
- Service layer: update Updater[ScalingGroupRow](pk_value=name) and Purger(row_class=ScalingGroupRow, pk_value=name) call sites in services/scaling_group/, api/gql_legacy/scaling_group.py, api/adapters/resource_group/adapter.py.
- Tests: FK integrity, cascade behavior, fair-share/scheduler correctness; update test fixtures using Purger/Updater with name.

Depends on

BA-6048 (done), BA-6707, BA-6708, BA-6713 (id columns must exist and session name column must already be dropped).

JIRA Issue: BA-6050

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.