mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 07:56:52 +08:00
refactor: migrate high-risk write transactions
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from sqlalchemy import delete
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import DbOper
|
||||
from app.db.models.plugindata import PluginData
|
||||
|
||||
@@ -82,6 +85,15 @@ class PluginDataOper(DbOper):
|
||||
else:
|
||||
PluginData.del_plugin_data(self._db, plugin_id)
|
||||
|
||||
def stage_delete(self, plugin_id: str) -> None:
|
||||
"""暂存目标插件全部数据删除并 flush,不提交调用方事务。"""
|
||||
if not isinstance(self._db, Session):
|
||||
raise RuntimeError("插件数据暂存删除需要调用方提供 Session")
|
||||
self._db.execute(
|
||||
delete(PluginData).where(PluginData.plugin_id == plugin_id)
|
||||
)
|
||||
self._db.flush()
|
||||
|
||||
def truncate(self):
|
||||
"""
|
||||
清空插件数据
|
||||
|
||||
Reference in New Issue
Block a user