refactor: finish transactional runtime migration

This commit is contained in:
jxxghp
2026-08-22 15:18:16 +08:00
parent fe2e6809f7
commit be18cace1f
59 changed files with 1006 additions and 568 deletions
+4 -4
View File
@@ -7,7 +7,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Mapped, Session, mapped_column
from app.db.base import Base, execute_dml, get_id_column
from app.db.decorators import async_db_query, db_query, db_update
from app.db.decorators import async_db_query, db_query
from app.db.models._constraints import media_identity_constraint
from app.schemas.types import MediaSource
@@ -65,16 +65,16 @@ class MediaServerItem(Base):
).scalars().first()
@classmethod
@db_update
def empty(cls, db: Session, server: Optional[str] = None):
"""在调用方事务中暂存媒体服务器条目清空操作。"""
statement = delete(cls)
if server is not None:
statement = statement.where(cls.server == server)
db.execute(statement, execution_options={"synchronize_session": False})
@classmethod
@db_update
def delete_stale(cls, db: Session, server: str, sync_time: str):
"""在调用方事务中删除本轮同步未更新的条目。"""
return execute_dml(
db,
delete(cls).where(
@@ -85,8 +85,8 @@ class MediaServerItem(Base):
)
@classmethod
@db_update
def delete_excluded_servers(cls, db: Session, servers: List[str]):
"""在调用方事务中删除不属于启用服务器的条目。"""
statement = delete(cls)
if servers:
statement = statement.where(