Skip to content

feat(pam): add MySQL web access data explorer#7022

Merged
bernie-g merged 17 commits into
pam-revampfrom
bernie/pam-291-add-support-for-mysql-web-access
Jun 26, 2026
Merged

feat(pam): add MySQL web access data explorer#7022
bernie-g merged 17 commits into
pam-revampfrom
bernie/pam-291-add-support-for-mysql-web-access

Conversation

@bernie-g

Copy link
Copy Markdown
Contributor

Summary

  • Add browser-based MySQL data explorer matching the existing Postgres implementation, with dialect-aware SQL generation, statement splitting, metadata queries, filtering, sorting, inline editing, and transaction tracking.

Type of change

  • New feature

Test plan

  • Unit tests for splitMysqlStatements and extractCommand (30 tests covering doubled-quote escapes, unterminated strings/comments, block comments, all statement types)
  • Unit test update for buildPamAccountTypeMetadata to include MySQL in supported web-access set
  • Manual browser testing of table loading, switching, filtering (LIKE), sorting, inline editing, transaction tracking (BEGIN/ROLLBACK/COMMIT), error handling, JSON/date/time/enum column rendering, and NULL display

bernie-g added 3 commits June 24, 2026 16:16
Add browser-based data explorer for MySQL PAM accounts, matching the
existing Postgres implementation. Extract shared session handler logic
into a dialect-agnostic factory to deduplicate ~85% of the session
handler code between Postgres and MySQL.

Backend:
- Add MySQL connection controller, metadata queries, and session handler
- Extract shared ws-types (enums, Zod schemas, types) into
  pam-data-explorer-ws-types.ts
- Extract shared session handler into createDataExplorerSessionHandler
  factory in pam-data-explorer-session-handler.ts
- Rewrite Postgres session handler as thin wrapper using the factory
- Add splitMysqlStatements parser with unit tests
- Register MySQL handler in pam-session-handlers.ts

Frontend:
- Add SqlDialect type to parameterize SQL generation (quoting, ILIKE,
  RETURNING, dollar-quoting, transactions)
- Thread dialect through DataExplorerGrid, toolbar, and filter popover
- Use sequential statement execution for MySQL instead of
  BEGIN/COMMIT wrapping
- Default MySQL schema to the connection's database name
- Hide ILIKE filter operator for MySQL
- Fix extractCommand to skip leading comments before extracting the SQL keyword
- Add # comment support to splitMysqlStatements
- Set max_execution_time and sql_select_limit session variables to prevent runaway queries and unbounded memory
- Add end event listener and cancel connection error listener
- Move ORDER BY inside JSON_ARRAYAGG for deterministic column ordering
- Use wrapInTransaction for atomic MySQL saves in the frontend
- Deduplicate OneShotOptions type across dialect metadata files
- Replace old test file with properly named tests covering both functions (25 tests)
Fix statement splitter to handle doubled-quote escapes, add implicit
commit detection for DDL, fix sql_select_limit parameterization, add
MySQL backslash escaping in quoteLiteral, deduplicate ControllerParams
type, use derived-table subqueries for MySQL 8.0 compat, add MySQL
dialect to SQL editor and filter popover, fix dependency arrays.
@linear

linear Bot commented Jun 24, 2026

Copy link
Copy Markdown

PAM-291

@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-infisical-7022-feat-pam-add-mysql-web-access-data-explorer

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

bernie-g added 3 commits June 24, 2026 20:51
…sh escape in backtick identifiers, add metadata query timeout
MySQL max_execution_time only covers SELECTs. Wrap each user query
with a 30s timer that fires KILL QUERY for unbounded DML/DDL.
…add-support-for-mysql-web-access

# Conflicts:
#	frontend/src/pages/pam/PamAccountAccessPage/PamAccountAccessPage.tsx
@bernie-g bernie-g marked this pull request as ready for review June 25, 2026 01:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d492a75c94

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a MySQL data explorer to the PAM web access feature, mirroring the existing Postgres implementation. The shared session-handler factory (createDataExplorerSessionHandler) is a clean abstraction that eliminates duplication, and the custom MySQL statement splitter is well-tested.

  • New MySQL backend: per-tab connection controller with KILL QUERY–based DML timeout, information_schema metadata queries, and a 30-test statement splitter/command extractor.
  • Shared session handler factory extracted from the Postgres path so both dialects use identical connection-lifecycle, metadata-queuing, and WebSocket message-routing logic.
  • Frontend SQL generation extended with MySQL dialect support (backtick identifiers, backslash escaping, dialect-aware INSERT/UPDATE without RETURNING).

Confidence Score: 4/5

Safe to merge for typical MySQL deployments; the two non-trivial findings are edge-case UI-state and data-correctness issues that do not affect the happy path.

The core query execution, cancellation, metadata retrieval, and statement splitting are all correct and well-tested. UNLOCK TABLES in the implicit-commit set can make the UI report a transaction as closed when it is still open — confusing but not data-corrupting. The MySQL quoteLiteral backslash-doubling produces wrong stored values if the target server has NO_BACKSLASH_ESCAPES in its SQL mode, which is a non-default but legal server configuration.

pam-mysql-connection-controller.ts (implicit-commit command set) and sql-generation.ts (backslash escaping for MySQL) warrant a second look before targeting servers with non-default SQL modes.

Important Files Changed

Filename Overview
backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts New MySQL per-tab connection controller: handles query execution, cancellation via KILL QUERY, transaction state tracking, and error handling. Missing explicit multipleStatements: false (unlike one-shot connection); UNLOCK in implicit-commit set may produce stale UI state.
frontend/src/pages/pam/PamDataExplorerPage/sql-generation.ts Extended SQL generation with MySQL dialect support (backtick quoting, backslash escaping). Backslash doubling in quoteLiteral is incorrect if target MySQL runs with NO_BACKSLASH_ESCAPES mode.
backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.ts New MySQL statement splitter and command extractor with 30 unit tests. Correctly handles doubled-quote escapes, backtick identifiers, hash comments, block comments, and the MySQL-specific -- comment rule.
backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-metadata.ts Parameterized information_schema queries for schemas, tables, and full table detail (columns, PKs, FKs) using JSON_OBJECT aggregation. No injection vectors; all user-supplied values are bound parameters.
backend/src/ee/services/pam-web-access/pam-data-explorer-session-handler.ts New shared WebSocket session handler factory extracted from the Postgres implementation; manages connection lifecycle, metadata queuing, and message routing for any SQL dialect.
backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts One-shot MySQL connection helpers for schema/table enumeration and reachability checks. Explicitly sets multipleStatements: false and max_execution_time.
backend/src/ee/services/pam-web-access/mysql/pam-mysql-session-handler.ts Thin adapter wiring MySQL-specific implementations into the shared createDataExplorerSessionHandler factory.
backend/src/ee/services/pam-web-access/pam-session-handlers.ts Registers MySQL handler alongside existing Postgres and SSH handlers in the session-handler dispatch table.
backend/src/ee/services/pam-web-access/postgres/pam-postgres-session-handler.ts Refactored Postgres session handler now delegates to the shared createDataExplorerSessionHandler factory; no behavioral change.
frontend/src/pages/pam/PamDataExplorerPage/PamDataExplorerPage.tsx Data explorer page now detects MySQL account type and derives the correct dialect and default schema; all existing layout and session logic unchanged.
backend/src/ee/services/pam-account/pam-account-schemas.test.ts Unit test updated to include MySQL in the supported web-access set and assert supportsWebAccess: true for MySQL.
backend/src/ee/services/pam-web-access/mysql/pam-mysql-data-explorer-fns.test.ts Comprehensive test suite (30 cases) for MySQL statement splitting and command extraction covering all comment styles, quoting, escape sequences, and transaction keywords.

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/pam..." | Re-trigger Greptile

Comment thread backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/sql-generation.ts
Comment thread backend/src/ee/services/pam-web-access/mysql/pam-mysql-connection-controller.ts Outdated
@veria-ai

veria-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 2 · PR risk: 0/10

@bernie-g bernie-g requested a review from saifsmailbox98 June 25, 2026 14:13
bernie-g added 3 commits June 25, 2026 12:02
Replace manual IMPLICIT_COMMIT_COMMANDS set with server-side transaction
state detection via DO 0 + SERVER_STATUS_IN_TRANS flag. Covers all
implicit commit cases automatically without maintaining a command list.
Prevents users from bypassing the row cap by running
SET SESSION sql_select_limit=DEFAULT before a query.
Add supportBigNumbers, bigNumberStrings, and dateStrings options to
prevent precision loss on BIGINTs above MAX_SAFE_INTEGER and timezone
shifts on date/time columns.
Comment thread backend/src/ee/services/pam-web-access/mysql/pam-mysql-metadata.ts
Comment thread backend/src/ee/services/pam-web-access/pam-data-explorer-ws-types.ts Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/QueryPanel.tsx Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/DataExplorerGrid.tsx Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/sql-generation.ts Outdated
bernie-g added 4 commits June 25, 2026 19:13
… error handler

Rename backendPid to nativeConnectionId across backend and frontend
for database-agnostic terminology. Add conn.on("error") handler to
MySQL metadata one-shot connections matching the Postgres pattern.
@bernie-g bernie-g merged commit 986b43e into pam-revamp Jun 26, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants