Optimize SQL script execution in the CLI (#1181)

This commit is contained in:
Wu Clan
2026-05-25 11:06:06 +08:00
committed by GitHub
parent 2e86d79150
commit dbfdc6762e
+4 -2
View File
@@ -504,8 +504,9 @@ async def execute_sql_scripts(db: AsyncSession, sql_scripts: str, *, is_init: bo
"""解析并执行 SQL 脚本"""
try:
stmts = await parse_sql_script(sql_scripts)
conn = await db.connection()
for stmt in stmts:
await db.execute(text(stmt))
await conn.exec_driver_sql(stmt)
except Exception as e:
raise cappa.Exit(f'SQL 脚本执行失败:{e}', code=1)
@@ -517,8 +518,9 @@ async def execute_destroy_sql_scripts(db: AsyncSession, sql_scripts: str) -> Non
"""执行插件销毁 SQL 脚本"""
try:
stmts = await parse_sql_script(sql_scripts, is_destroy=True)
conn = await db.connection()
for stmt in stmts:
await db.execute(text(stmt))
await conn.exec_driver_sql(stmt)
except Exception as e:
raise cappa.Exit(f'销毁 SQL 脚本执行失败:{e}', code=1)