Skip to content

Commit c2df8f5

Browse files
committed
refactor: Migrate models to app.db and update imports across the codebase
1 parent 7e7df6e commit c2df8f5

File tree

13 files changed

+32
-23
lines changed

13 files changed

+32
-23
lines changed

app/api/legacy_downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sqlmodel import Session
1111

1212
from app.core.scheduler import schedule_download, RUNNING, RUNNING_LOCK
13-
from app.models import get_session, get_job as db_get_job
13+
from app.db import get_session, get_job as db_get_job
1414

1515
from app.core.downloader import Provider, Language
1616

app/api/qbittorrent/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from loguru import logger
66
from sqlmodel import Session
77

8-
from app.models import get_session, get_job
8+
from app.db import get_session, get_job
99

1010
from . import router
1111
from .common import CATEGORIES, public_save_path
@@ -17,7 +17,7 @@ def sync_maindata(session: Session = Depends(get_session)):
1717
"""Minimal maindata dump accepted by Sonarr."""
1818
logger.debug("Sync maindata requested.")
1919
from sqlmodel import select
20-
from app.models import ClientTask
20+
from app.db import ClientTask
2121
import os
2222
import time
2323

app/api/qbittorrent/torrents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
DELETE_FILES_ON_TORRENT_DELETE,
1515
)
1616
from app.utils.magnet import parse_magnet
17-
from app.models import (
17+
from app.db import (
1818
get_session,
1919
upsert_client_task,
2020
get_client_task,
@@ -99,7 +99,7 @@ def torrents_info(
9999
"""List torrents (ClientTasks) in qBittorrent-compatible subset."""
100100
logger.debug("Fetching torrents info.")
101101
from sqlmodel import select
102-
from app.models import ClientTask
102+
from app.db import ClientTask
103103
import os
104104

105105
rows = session.exec(select(ClientTask)).all()

app/api/torznab/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from app.utils.naming import build_release_name # noqa: E402
3838
from app.utils.probe_quality import probe_episode_quality # noqa: E402
3939
from app.utils.magnet import build_magnet # noqa: E402
40-
from app.models import ( # noqa: E402
40+
from app.db import ( # noqa: E402
4141
get_session,
4242
get_availability,
4343
list_available_languages_cached,
@@ -69,4 +69,3 @@
6969
"list_available_languages_cached",
7070
"upsert_availability",
7171
]
72-

app/api/torznab/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
TORZNAB_TEST_SLUG,
1919
TORZNAB_TEST_TITLE,
2020
)
21-
from app.models import get_session
21+
from app.db import get_session
2222

2323
from . import router
2424
from .utils import _build_item, _caps_xml, _require_apikey, _rss_root

app/core/lifespan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727

2828
from app.core.scheduler import init_executor, shutdown_executor
29-
from app.models import (
29+
from app.db import (
3030
engine,
3131
dispose_engine,
3232
create_db_and_tables,

app/core/scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
ProgressSnapshot,
1313
is_interactive_terminal,
1414
)
15-
from app.models import engine, create_job, update_job
15+
from app.db import engine, create_job, update_job
1616
from app.core.downloader import download_episode, Provider, Language
1717
from app.utils.logger import config as configure_logger
1818

@@ -47,7 +47,7 @@ def shutdown_executor() -> None:
4747

4848
def _progress_updater(job_id: str, stop_event: threading.Event):
4949
from sqlmodel import Session
50-
from app.models import engine, update_job
50+
from app.db import engine, update_job
5151

5252
reporter: ProgressReporter | None = None
5353
last_db_n = -1

app/db/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Database package: SQLModel models, engine, and CRUD helpers.
2+
3+
This package contains the SQLite/SQLModel data models and related utilities
4+
that used to live in `app/models.py`. Functionality and public API are preserved;
5+
imports should now use `from app.db import ...`.
6+
"""
7+
8+
from .models import * # re-export full surface for backwards compatibility
9+
10+
__all__ = [name for name in globals() if not name.startswith("_")]
11+

app/models.py renamed to app/db/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ class ClientTask(ModelBase, table=True):
126126
) # queued/downloading/paused/completed/error
127127

128128

129-
import os
130-
131-
# --- DB Bootstrap (use central DATA_DIR from config)
132-
logger.debug(f"DATA_DIR for jobs DB: {DATA_DIR}")
129+
# ---------------- Engine and Session utilities
133130
DATABASE_URL = f"sqlite:///{(DATA_DIR / 'anibridge_jobs.db').as_posix()}"
134131
logger.debug(f"DATABASE_URL: {DATABASE_URL}")
135132

@@ -402,3 +399,4 @@ def delete_client_task(session: Session, hash: str) -> None:
402399
logger.success(f"Deleted client task for hash {hash}")
403400
else:
404401
logger.warning(f"Client task for hash {hash} not found, nothing to delete.")
402+

app/domain/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"""Compatibility shim: re-export models from `app.models`.
1+
"""Compatibility shim: re-export models from `app.db`.
22
3-
Keeping `app.models` as the canonical definition allows pytest to reset
3+
Keeping `app.db` as the canonical definition allows pytest to reset
44
metadata by purging that module name. This module simply forwards imports
55
for readability under `app.domain`.
66
"""
77

8-
from app.models import * # noqa: F401,F403
8+
from app.db import * # noqa: F401,F403

0 commit comments

Comments
 (0)