mirror of
https://github.com/insistence/RuoYi-Vue3-FastAPI.git
synced 2026-10-04 09:11:00 +00:00
* feat: 初始化插件系统 * refactor: 收口插件系统运行时重构 * perf: 优化插件系统类型提示 * fix&perf: 修复和优化插件系统 * fix: 修复gitignore规则误忽略插件文件的问题 * fix: 修复运行时插件根路径算错的问题 * fix: 加强插件发现和路由注册的防护措施 * revert: 回滚定时任务白名单 * fix: 移除未使用的应用路由注册探测 * revert: 恢复部分代码 * perf: 优化插件系统 * docs: 新增插件开发文档 * perf: 优化插件管理模块 * perf: 提升插件系统核心能力 * refactor: 重构生命周期 step runner * fix: 修复lint错误 * test: 清理测试用例 * test: 调整测试目录名称 * fix: 修复前后端目录硬编码的问题 * fix: 修复插件系统安全性缺口 * refactor: 重新设计插件生命周期 Migration 事务与回滚 * perf: 优化插件系统边界问题 * refactor: 重构当前插件系统的依赖体系设计 * perf: 优化代码 * perf: 优化代码 * fix: 修复代码合并问题 * fix: 修复bug * perf: 优化代码 * perf&fix: 优化代码和修复bug * docs: 优化文档格式 * feat: 适配Vue2版本 * docs: 更新README文档 * fix: 修复ruff lint错误 * chore: 更新后端依赖文件
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from collections.abc import AsyncGenerator
|
|
from typing import Literal
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from config.database import AsyncSessionLocal, Base, async_engine
|
|
from utils.log_util import logger
|
|
|
|
|
|
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
"""
|
|
每一个请求处理完毕后会关闭当前连接,不同的请求使用不同的连接
|
|
|
|
:return:
|
|
"""
|
|
async with AsyncSessionLocal() as current_db:
|
|
yield current_db
|
|
|
|
|
|
async def init_create_table(
|
|
*,
|
|
stage: Literal['platform', 'plugin_entities'] = 'platform',
|
|
log_success_enabled: bool = True,
|
|
) -> None:
|
|
"""
|
|
应用启动时初始化数据库元数据。
|
|
|
|
:param stage: 建表阶段
|
|
:param log_success_enabled: 是否输出阶段成功摘要
|
|
:return: None
|
|
"""
|
|
if log_success_enabled:
|
|
message = '🔎 初始化平台数据库元数据...' if stage == 'platform' else '🔎 同步插件实体表...'
|
|
logger.bind(database_init_stage=stage).info(message)
|
|
async with async_engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
if log_success_enabled:
|
|
message = '✅️ 平台数据库元数据初始化完成' if stage == 'platform' else '✅️ 插件实体表同步完成'
|
|
logger.bind(database_init_stage=stage).info(message)
|
|
|
|
|
|
async def close_async_engine() -> None:
|
|
"""
|
|
应用关闭时释放数据库连接池
|
|
|
|
:return:
|
|
"""
|
|
await async_engine.dispose()
|