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
+20 -8
View File
@@ -6,8 +6,8 @@ Create Date: 2024-11-14 12:49:13.838120
"""
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 = 'a295e41830a6'
@@ -19,16 +19,28 @@ depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# 初始化AList存储
_systemconfig = SystemConfigOper()
_storages = _systemconfig.get(SystemConfigKey.Storages)
if _storages:
if "alist" not in [storage["type"] for storage in _storages]:
_storages.append({
systemconfig = sa.table(
"systemconfig",
sa.column("key", sa.String()),
sa.column("value", sa.JSON()),
)
connection = op.get_bind()
key = "Storages"
row = connection.execute(
sa.select(systemconfig.c.value).where(systemconfig.c.key == key)
).first()
_storages = row[0] if row else None
if _storages and "alist" not in [storage["type"] for storage in _storages]:
_storages.append({
"type": "alist",
"name": "AList",
"config": {}
})
_systemconfig.set(SystemConfigKey.Storages, _storages)
connection.execute(
systemconfig.update().where(systemconfig.c.key == key).values(
value=_storages
)
)
# ### end Alembic commands ###