INNER CODE UNIT · Python
remove_plugin
fastapi-practices/fba-slim · backend/cli.py:442
async def remove_plugin(plugin: str | None, *, no_sql: bool = False) -> None: # ruff:ignore[complex-structure]
"""卸载插件"""
if settings.ENVIRONMENT != 'dev':
raise cappa.Exit('插件卸载仅在开发环境可用', code=1)
async def remove() -> None:
plugin_dir = PLUGIN_DIR / plugin
if not plugin_dir.exists():
raise cappa.Exit(f'插件 {plugin} 不存在', code=1)
if not no_sql:
destroy_sql_file = await get_plugin_destroy_sql(plugin, settings.DATABASE_TYPE, settings.DATABASE_PK_MODE)
if destroy_sql_file:
console.note(f'正在执行插件 {plugin} 销毁 SQL 脚本:{destroy_sql_file}')
async with async_db_session.begin() as db:
await execute_destroy_sql_scripts(db, destroy_sql_file)
else:
console.warning(f'插件 {plugin} 未提供销毁 SQL 脚本,跳过数据库清理')