Files
MoviePilot/database/versions/41ef1dd7467c_2_2_2.py
Aqr-K d51320103c fix: make local setup and bundled skill operations recoverable (#7150)
* fix: make local setup and bundled skill operations recoverable

* test: verify user updates with real transaction runners
2026-10-23 06:49:13 +08:00

54 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
2.2.2 清理重复系统配置,每个配置键保留最大 ID 对应记录。
版本标识: 41ef1dd7467c
前置版本: a946dae52526
创建时间: 2026-01-13 13:02:41.614029
"""
from alembic import op
from sqlalchemy import text
from app.runtime.log import logger
# Alembic 使用以下标识连接迁移版本链。
revision = "41ef1dd7467c"
down_revision = "a946dae52526"
branch_labels = None
depends_on = None
def upgrade() -> None:
"""
清理重复系统配置,每个配置键保留最大 ID 对应记录。
"""
connection = op.get_bind()
select_stmt = text(
"""
SELECT id, key
FROM SystemConfig
WHERE id NOT IN (
SELECT MAX(id)
FROM SystemConfig
GROUP BY key
)
"""
)
to_delete = connection.execute(select_stmt).fetchall()
for row in to_delete:
logger.warn(
f"已删除重复的 SystemConfig 项:key={row.key}, id={row.id}"
)
delete_stmt = text("DELETE FROM SystemConfig WHERE id = :id")
connection.execute(delete_stmt, {"id": row.id})
logger.info("SystemConfig 表去重操作已完成。")
def downgrade() -> None:
"""
本版本不执行回退操作,保留升级后的结构与数据。
"""
pass