mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
fix(database): keep migrations in alembic transactions (#6400)
This commit is contained in:
@@ -6,8 +6,8 @@ Create Date: 2024-10-16 15:05:01.775429
|
||||
|
||||
"""
|
||||
|
||||
from app.db.oper.systemconfig import SystemConfigOper
|
||||
from app.schemas.types import SystemConfigKey
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'a73f2dbf5c09'
|
||||
@@ -19,7 +19,25 @@ depends_on = None
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
# 初始化下载优先规则
|
||||
SystemConfigOper().set(SystemConfigKey.TorrentsPriority, ["torrent", "upload", "seeder"])
|
||||
systemconfig = sa.table(
|
||||
"systemconfig",
|
||||
sa.column("key", sa.String()),
|
||||
sa.column("value", sa.JSON()),
|
||||
)
|
||||
connection = op.get_bind()
|
||||
key = "TorrentsPriority"
|
||||
value = ["torrent", "upload", "seeder"]
|
||||
row = connection.execute(
|
||||
sa.select(systemconfig.c.value).where(systemconfig.c.key == key)
|
||||
).first()
|
||||
if row and row[0] != value:
|
||||
connection.execute(
|
||||
systemconfig.update().where(systemconfig.c.key == key).values(
|
||||
value=value
|
||||
)
|
||||
)
|
||||
elif not row:
|
||||
connection.execute(systemconfig.insert().values(key=key, value=value))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user