feat:新增投顾agent和nl2sqlagent
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""执行 NL2SQL 验收账号和最小权限种子 SQL。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from config.database.mysql import dispose, get_session_factory
|
||||
|
||||
|
||||
SQL_PATH = Path(__file__).resolve().parents[1] / "sql" / "nl2sql_acceptance_seed.sql"
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
"""执行幂等种子文件并输出非敏感核验信息。"""
|
||||
statements = [item.strip() for item in SQL_PATH.read_text(encoding="utf-8").split(";") if item.strip()]
|
||||
async with get_session_factory()() as db:
|
||||
for statement in statements:
|
||||
await db.execute(text(statement))
|
||||
await db.commit()
|
||||
user_result = await db.execute(
|
||||
text(
|
||||
"SELECT id, username, user_type, employee_role, status "
|
||||
"FROM sys_user WHERE username = 'nl2sql_acceptance'"
|
||||
)
|
||||
)
|
||||
role_result = await db.execute(
|
||||
text(
|
||||
"SELECT id, role_code, can_query, status "
|
||||
"FROM nl2sql_query_role WHERE role_code = 'nl2sql_acceptance'"
|
||||
)
|
||||
)
|
||||
permission_result = await db.execute(
|
||||
text(
|
||||
"SELECT table_name, COUNT(*) AS column_count "
|
||||
"FROM nl2sql_role_column_permission "
|
||||
"WHERE role_id = (SELECT id FROM nl2sql_query_role "
|
||||
"WHERE role_code = 'nl2sql_acceptance') AND status = 'active' "
|
||||
"GROUP BY table_name ORDER BY table_name"
|
||||
)
|
||||
)
|
||||
print({"user": [dict(row) for row in user_result.mappings().all()]})
|
||||
print({"role": [dict(row) for row in role_result.mappings().all()]})
|
||||
print({"permissions": [dict(row) for row in permission_result.mappings().all()]})
|
||||
await dispose()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user