feat: 插件开发 ozon 端主体完成
This commit is contained in:
+11
-1
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
@@ -38,10 +39,19 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
yield session
|
||||
|
||||
|
||||
async def _migrate(conn) -> None:
|
||||
"""给旧库补充新增列(create_all 不会修改已存在的表)。"""
|
||||
rows = await conn.execute(text("PRAGMA table_info(suites)"))
|
||||
cols = {row[1] for row in rows}
|
||||
if "model" not in cols:
|
||||
await conn.execute(text("ALTER TABLE suites ADD COLUMN model VARCHAR(64)"))
|
||||
|
||||
|
||||
async def init_db() -> None:
|
||||
"""启动时建表(MVP 不引 Alembic,模型变更删库重建即可)。"""
|
||||
"""启动时建表 + 轻量列迁移(MVP 不引 Alembic)。"""
|
||||
import models # noqa: F401 确保模型注册
|
||||
|
||||
engine = get_engine()
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
await _migrate(conn)
|
||||
|
||||
Reference in New Issue
Block a user