mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 03:57:30 +08:00
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
49 lines
1.0 KiB
Python
49 lines
1.0 KiB
Python
"""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
|