fix(database): keep migrations in alembic transactions (#6400)

This commit is contained in:
InfinityPacer
2026-08-23 00:27:55 +08:00
committed by GitHub
parent a59f1b928a
commit 176d9255e5
16 changed files with 659 additions and 154 deletions
+23 -6
View File
@@ -6,8 +6,8 @@ Create Date: 2024-09-11 08:07:02.753307
"""
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 = '262735d025da'
@@ -19,9 +19,18 @@ depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# 初始化消息通知范围
_systemconfig = SystemConfigOper()
if not _systemconfig.get(SystemConfigKey.NotificationSwitchs):
_systemconfig.set(SystemConfigKey.NotificationSwitchs, [
systemconfig = sa.table(
"systemconfig",
sa.column("key", sa.String()),
sa.column("value", sa.JSON()),
)
connection = op.get_bind()
key = "NotificationSwitchs"
row = connection.execute(
sa.select(systemconfig.c.value).where(systemconfig.c.key == key)
).first()
if not row or not row[0]:
value = [
{
'type': '资源下载',
'action': 'all',
@@ -54,7 +63,15 @@ def upgrade() -> None:
'type': '其它',
'action': 'admin',
},
])
]
if row:
connection.execute(
systemconfig.update().where(systemconfig.c.key == key).values(
value=value
)
)
else:
connection.execute(systemconfig.insert().values(key=key, value=value))
# ### end Alembic commands ###