lablup / lablup/backend.ai

Restructure models into subpackages and remove eager imports

Open
#7,676 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

## Overview

Restructure the models package into domain-based subpackages and remove eager imports from `models/__init__.py`.

## Current State

- `models/__init__.py` eagerly imports all 40+ model modules
- Any import from `models/` loads everything
- ~35 files import from `models/__init__.py` (20 in src/, 15 in tests/)

## Target Structure

```
models/
├── __init__.py # Minimal exports (metadata only)
├── base.py # Base, metadata, common column types
├── domain/
│ ├── __init__.py # from .row import DomainRow
│ └── row.py # DomainRow definition
├── user/
│ ├── __init__.py
│ └── row.py
├── group/
│ └── ...
└── ...
```

## Tasks

- [ ] Create domain-based subpackage structure
- [ ] Move Row classes to respective subpackages
- [ ] Remove eager imports from `models/__init__.py`
- [ ] Update import paths in src/ (~20 files)
- [ ] Update import paths in tests/ (~15 files)

## Acceptance Criteria

- [ ] Repository transitive dependencies only include Row classes they actually use
- [ ] `alembic revision --autogenerate` detects all Row classes
- [ ] All tests pass
- [ ] Type checks pass
- [ ] Lint checks pass

## Verification Commands

```bash
# Check repository dependencies
pants dependencies --transitive tests/unit/manager/repositories/auth/test_auth_repository.py | grep "models/"

# Verify Alembic detection
./py -m alembic revision --autogenerate -m "test" --sql
```

JIRA Issue: BA-3619

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.