Repository navigation
feat(studio): logs SQL brands + execution data layer - #48301
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds branded handling for user-authored logs SQL and a SQL execution mutation with time-range parameters, normalized errors, React Query integration, toast handling, and tests. ChangesLogs SQL execution
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SQLEditor
participant Mutation
participant AnalyticsBackend
participant Toast
SQLEditor->>Mutation: submit logs SQL and date range
Mutation->>AnalyticsBackend: execute SQL with ISO timestamps
AnalyticsBackend-->>Mutation: rows or query error
Mutation->>Toast: display normalized error when needed
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/data/logs/execute-logs-sql-mutation.ts`:
- Around line 69-78: Update the error normalization logic around
RawLogsResponseError so it verifies structured.errors is an array before calling
.find(). For malformed values such as { errors: {} }, skip nested-message
extraction and continue returning the normalized fallback error without
throwing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f246ab8c-20cf-43a6-ae70-e448c9ebc12a
📒 Files selected for processing (4)
apps/studio/data/logs/execute-logs-sql-mutation.test.tsapps/studio/data/logs/execute-logs-sql-mutation.tsapps/studio/data/logs/safe-analytics-sql.test.tsapps/studio/data/logs/safe-analytics-sql.ts
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
🎭 Playwright Test Results (next)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
First PR in the SQL-editor query-source (Database vs Logs) stack.
Pure additions, no behavior change and no consumers yet:
- Add distinct untrusted/safe brands for user-authored logs SQL
(UntrustedLogSqlFragment, untrustedLogSql, acceptUntrustedLogsSql) in
safe-analytics-sql.ts, mirroring pg-meta's UntrustedSqlFragment but kept
disjoint so Postgres and logs SQL can never cross boundaries.
- Add data/logs/execute-logs-sql-mutation.ts: executeLogsSql wraps
executeAnalyticsSql, attaches the resolved range as request params (never
spliced into SQL), and normalizes to { rows, error? }; mapLogsError
normalizes the analytics backend's structured 200-body error into the
{ message } shape the result pane reads; useExecuteLogsSqlMutation collapses
transport and 200-body errors into a single onError path.
- Unit tests for mapLogsError, the brands (incl. compile-time disjointness vs
pg-meta brands), and safe composition.
3ef31f2 to
75dec68
Compare
Braintrust eval report
|
…sql (#48305) ## What PR **2 of 9** in the SQL-editor query-source (Database vs Logs) stack. **Base:** `charislam/snippet-source-typing` (#48301) — this is a stacked PR; review/merge that one first. Client-side rename only — **the wire format is unchanged** (the platform API still stores and returns `content.sql`). This moves the frontend `LogSqlSnippets.Content` field to the branded `unchecked_sql`, matching `SqlSnippets.Content`, and hardens the remap boundary so the rename can't silently drop saved query text. ## Changes - **`types/userContent.ts`** — `LogSqlSnippets.Content`'s plain `sql: string` becomes `unchecked_sql: UntrustedLogSqlFragment` (the brand added in PR 1). Shape kept minimal: `{ content_id, unchecked_sql, schema_version }`. - **`data/content/content-remap.ts`** — extend `remapSqlContentField`/`unmapSqlContentField` to `log_sql`, branding **per type** (`untrustedLogSql` for logs, `untrustedSql` for database) and never mixing brands. **Defensive unmap**: content missing `unchecked_sql` is never clobbered with `sql: undefined`; a residual raw `sql` field (a missed save-path rename) throws in development to surface the bug loudly, while production no-ops safely. - **Legacy Logs Explorer consumers** updated to the branded field: the explorer save/update paths, `SavedQueriesItem`, `RecentQueriesItem`, and the recent-queries page. - **Two db-only write sites** that leaned on `LogSqlSnippets.Content.sql`: `EditorPanel` now saves `unchecked_sql`, and `MoveQueryModal` switches to the SQL-editor-specific `getSqlSnippetById` so its content is typed as `SqlSnippets.Content` — no narrowing or casting. ## Tests - **content-remap**: `log_sql` remap/unmap round-trip with the logs brand; the defensive-unmap no-op (prod) and dev throw. - **content-upsert-mutation**: a `log_sql` payload reaches the wire as a plain `content.sql` and the response remaps back to `unchecked_sql` (the data-loss-critical round-trip shared by both explorer save-new and `SavedQueriesItem` update). ## Verification - `pnpm --filter studio run typecheck` ✓ - `pnpm --filter studio run lint:ratchet` ✓ (no new warnings) - `pnpm test:studio` for `data/content` + `Settings/Logs` — 139 passing ✓ - Prettier ✓ Nothing is user-visible yet — logs snippet entry points arrive later in the stack behind the `sqlEditorLogsSource` flag. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of saved and recent log queries across the SQL editor and Logs Explorer. - Log SQL now uses `unchecked_sql` (branded as untrusted) consistently when creating, editing, moving, and reopening queries, with correct remapping to/from the API boundary. - Fixed saved-query update payloads to preserve the right query content and omit legacy fields. - **Tests** - Added/expanded Vitest coverage for saved log query editing, recent-log normalization, and `log_sql` remap/upsert request/response behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Feature (data layer only — PR 1 of the SQL-editor query-source stack; nothing user-visible yet, no consumers).
What is the current behavior?
The Studio SQL editor only runs queries against Postgres. There is no type-safe brand for user-authored logs SQL and no execution/normalization layer for running SQL against the logs/analytics (ClickHouse) backend.
What is the new behavior?
Pure additions, no behavior change:
data/logs/safe-analytics-sql.ts— adds distinct untrusted/safe brands for user-authored logs SQL (UntrustedLogSqlFragment,untrustedLogSql,acceptUntrustedLogsSql), mirroring pg-meta'sUntrustedSqlFragmentbut kept intentionally disjoint so Postgres and logs SQL can never cross boundaries.data/logs/execute-logs-sql-mutation.ts(new) —executeLogsSqlwrapsexecuteAnalyticsSql, attaches the resolved time range as request params (iso_timestamp_start/end, never spliced into SQL), and normalizes to{ rows, error? };mapLogsErrornormalizes the analytics backend's structured 200-body error into the{ message }shape the result pane reads;useExecuteLogsSqlMutationcollapses transport and 200-body errors into React Query's singleonErrorpath.mapLogsError, the brands (including compile-time disjointness vs pg-meta brands), and safe composition.Verification:
pnpm test:studio(new suites, 26 passed),pnpm typecheck,lint:ratchet(no new warnings), and Prettier all pass.Additional context
Summary by CodeRabbit