fix(db): 补回 system_configs.description 列(修复 /admin/config 500)
- 此前 MySQL 适配时模型编辑误删 description,导致仓储序列化 AttributeError - 0037_system_config_description:幂等补列(SQLite 已有则跳过)并回填存量说明 - 与并行的 0037_market 分叉建 merge 版本,统一迁移线(当前 head=02d10eccb1f9)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""补回 system_configs.description(此前模型编辑误删,导致 /admin/config 500)。
|
||||
|
||||
Revision ID: 0037_system_config_description
|
||||
Revises: 0036_service_orders
|
||||
Create Date: 2026-08-31
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "0037_system_config_description"
|
||||
down_revision = "0036_service_orders"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""SQLite 已有该列 → 仅 MySQL/缺失时补;幂等(查列存在性)。"""
|
||||
bind = op.get_bind()
|
||||
insp = sa.inspect(bind)
|
||||
cols = [c["name"] for c in insp.get_columns("system_configs")]
|
||||
if "description" not in cols:
|
||||
op.add_column("system_configs", sa.Column("description", sa.String(), nullable=True, server_default=""))
|
||||
# 从 SQLite 备份源回填说明(如存在)
|
||||
try:
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
db_path = Path("serverdata/data/app.db")
|
||||
if db_path.exists():
|
||||
sconn = sqlite3.connect(str(db_path))
|
||||
rows = sconn.execute("SELECT key, description FROM system_configs").fetchall()
|
||||
sconn.close()
|
||||
from sqlalchemy import text
|
||||
for k, d in rows:
|
||||
if d:
|
||||
bind.execute(text("UPDATE system_configs SET description=:d WHERE `key`=:k"),
|
||||
{"d": d, "k": k})
|
||||
except Exception: # noqa: BLE001 回填失败不阻塞
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
pass # 保留列(回滚会造成数据丢失)
|
||||
@@ -0,0 +1,25 @@
|
||||
"""merge market 与 system_config_description 分支
|
||||
|
||||
Revision ID: 02d10eccb1f9
|
||||
Revises: 0037_market, 0037_system_config_description
|
||||
Create Date: 2026-08-31 23:44:52.597833
|
||||
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '02d10eccb1f9'
|
||||
down_revision = ('0037_market', '0037_system_config_description')
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
pass
|
||||
@@ -388,6 +388,7 @@ class SystemConfig(Base):
|
||||
|
||||
key: Mapped[str] = mapped_column(String, primary_key=True)
|
||||
value: Mapped[str] = mapped_column(Text, default="") # 配置值(存量可达 300+ 字节,MySQL 用 MEDIUMTEXT)
|
||||
description: Mapped[str] = mapped_column(String, default="") # 配置说明(0037 补回:此前模型误删)
|
||||
updated_at: Mapped[str] = mapped_column(String, default="")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user