Add support for pg_stat_statements configuration in Targets

This commit introduces a `use_pg_stat_statements` flag for targets, allowing users to enable or disable the use of `pg_stat_statements` for query insights. It includes database schema changes, backend logic, and UI updates to manage this setting in both creation and editing workflows.
This commit is contained in:
2026-02-12 13:39:57 +01:00
parent 839943d9fd
commit 712bec3fea
8 changed files with 215 additions and 15 deletions

View File

@@ -64,6 +64,7 @@ async def create_target(
username=payload.username,
encrypted_password=encrypt_secret(payload.password),
sslmode=payload.sslmode,
use_pg_stat_statements=payload.use_pg_stat_statements,
tags=payload.tags,
)
db.add(target)
@@ -188,6 +189,11 @@ async def get_activity(target_id: int, user: User = Depends(get_current_user), d
@router.get("/{target_id}/top-queries", response_model=list[QueryStatOut])
async def get_top_queries(target_id: int, user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)) -> list[QueryStatOut]:
_ = user
target = await db.scalar(select(Target).where(Target.id == target_id))
if not target:
raise HTTPException(status_code=404, detail="Target not found")
if not target.use_pg_stat_statements:
return []
rows = (
await db.scalars(
select(QueryStat)