refactor: 统一 sqlmodel_ext 用法至官方推荐模式
Some checks failed
Test / test (push) Failing after 3m47s

- 替换 Field(max_length=X) 为 StrX/TextX 类型别名(21 个 sqlmodels 文件)
- 替换 get + 404 检查为 get_exist_one()(17 个路由文件,约 50 处)
- 替换 save + session.refresh 为 save(load=...)
- 替换 session.add + commit 为 save()(dav/provider.py)
- 更新所有依赖至最新版本

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 11:13:16 +08:00
parent 9185f26b83
commit 6c96c43bea
57 changed files with 1091 additions and 761 deletions

View File

@@ -147,7 +147,7 @@ async def migrate_single_file(
# 4. 更新 Object
obj.policy_id = dest_policy.id
obj.physical_file_id = new_physical.id
await obj.save(session)
obj = await obj.save(session)
# 5. 旧 PhysicalFile 引用计数 -1
old_physical.decrement_reference()
@@ -159,7 +159,7 @@ async def migrate_single_file(
l.warning(f"删除源文件失败(不影响迁移结果): {old_physical.storage_path}: {e}")
await PhysicalFile.delete(session, old_physical)
else:
await old_physical.save(session)
old_physical = await old_physical.save(session)
l.info(f"文件迁移完成: {obj.name} ({obj.id}), {src_policy.name}{dest_policy.name}")
@@ -187,12 +187,12 @@ async def migrate_file_with_task(
task.status = TaskStatus.COMPLETED
task.progress = 100
await task.save(session)
task = await task.save(session)
except Exception as e:
l.error(f"文件迁移任务失败: {obj.id}: {e}")
task.status = TaskStatus.ERROR
task.error = str(e)[:500]
await task.save(session)
task = await task.save(session)
async def migrate_directory_files(
@@ -244,7 +244,7 @@ async def migrate_directory_files(
# 更新所有子目录的 policy_id
for sub_folder in folders_to_update:
sub_folder.policy_id = dest_policy.id
await sub_folder.save(session)
sub_folder = await sub_folder.save(session)
# 完成任务
if errors:
@@ -254,7 +254,7 @@ async def migrate_directory_files(
task.status = TaskStatus.COMPLETED
task.progress = 100
await task.save(session)
task = await task.save(session)
l.info(
f"目录迁移完成: {folder.name} ({folder.id}), "
@@ -264,7 +264,7 @@ async def migrate_directory_files(
l.error(f"目录迁移任务失败: {folder.id}: {e}")
task.status = TaskStatus.ERROR
task.error = str(e)[:500]
await task.save(session)
task = await task.save(session)
async def _collect_objects_recursive(

View File

@@ -287,7 +287,7 @@ async def permanently_delete_objects(
await PhysicalFile.delete(session, physical_file, commit=False)
l.debug(f"物理文件记录已删除: {physical_file.storage_path}")
else:
await physical_file.save(session, commit=False)
physical_file = await physical_file.save(session, commit=False)
l.debug(f"物理文件仍有 {physical_file.reference_count} 个引用: {physical_file.storage_path}")
# 更新用户存储配额
@@ -399,7 +399,7 @@ async def delete_object_recursive(
await PhysicalFile.delete(session, physical_file, commit=False)
l.debug(f"物理文件记录已删除: {physical_file.storage_path}")
else:
await physical_file.save(session, commit=False)
physical_file = await physical_file.save(session, commit=False)
l.debug(f"物理文件仍有 {physical_file.reference_count} 个引用: {physical_file.storage_path}")
# 阶段三:更新用户存储配额(与删除在同一事务中)
@@ -458,7 +458,7 @@ async def _copy_object_recursive(
physical_file = await PhysicalFile.get(session, PhysicalFile.id == src_physical_file_id)
if physical_file:
physical_file.increment_reference()
await physical_file.save(session)
physical_file = await physical_file.save(session)
total_copied_size += src_size
new_obj = await new_obj.save(session)