Files
MoviePilot/database/versions/41ef1dd7467c_2_2_2.py
大虾 306c0b707b Update database/versions/41ef1dd7467c_2_2_2.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-01-24 02:53:14 +08:00

49 lines
1.0 KiB
Python
Raw 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
Revision ID: 41ef1dd7467c
Revises: a946dae52526
Create Date: 2026-01-13 13:02:41.614029
"""
from alembic import op
from sqlalchemy import text
from app.log import logger
# revision identifiers, used by Alembic.
revision = "41ef1dd7467c"
down_revision = "a946dae52526"
branch_labels = None
depends_on = None
def upgrade() -> None:
# systemconfig表 去重
connection = op.get_bind()
select_stmt = text(
"""
SELECT id, key, value
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}, value={row.value}, 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